• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
why is my download request using HTTP POST is split in header and body ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

why is my download request using HTTP POST is split in header and body ?


  • Subject: why is my download request using HTTP POST is split in header and body ?
  • From: "Hans Loonen" <email@hidden>
  • Date: Thu, 13 May 2004 10:50:37 +0200

Hi,

I'm new to the macnetworkprog list, but I did use the printing list and the
carbon list.
The following topic I already posted on the printing list, but I actually
have a problem concerning CFNetwork issues.

I'm working on a PDE that must download information from the printer it is
supposed to print to.
I've been working on this for a few weeks now and I use the CFNetworking
sample code: CFNetworkHTTPDownload.
I got the code running for downloading data from a server using HTTP GET.
So far so good.

I also should have this code working for downloading data using HTTP POST.
The protocol to achieve this looks like this:
QUOTE
POST /transfer HTTP/1.1
Content-Type: multipart/form-data; boundary=----ADP_05122004114824
User-Agent: InetURL/1.0
Host: 1xx.1xy.163.114
Content-Length: 455
Connection: Keep-Alive
Cache-Control: nocache

------ADP_05122004114824
Content-Disposition: form-data; name="username"

Intralogic
------ADP_05122004114824
Content-Disposition: form-data; name="password"

71617
------ADP_05122004114824
Content-Disposition: form-data; name="command"

download
------ADP_05122004114824
Content-Disposition: form-data; name="type"

scan
------ADP_05122004114824
Content-Disposition: form-data; name="name"

mediacat.xml
------ADP_05122004114824--


END QUOTE

Here is the code I adapted in the sample:

NEXT QUOTE
void DownloadURL( char *url ) {
.
.
messageRef = CFHTTPMessageCreateRequest( kCFAllocatorDefault,
CFSTR("POST"), urlRef, kCFHTTPVersion1_1 );
if ( messageRef == NULL )
{
fprintf(stderr, "CFHTTPMessageCreateRequest returned NULL");
goto Bail;
}

CHTTPSTransfer mytransfer;
sprintf(mytransfer.m_Target, "%s", url);
eErrors DownloadErr = do_download(&mytransfer); // do_download fills
the mytransfer struct, this struct contains all messagebody elements
char bodydata[1024];

sprintf(bodydata, "%s", mytransfer.m_MessageBody);
body = CFDataCreate(kCFAllocatorDefault, bodydata,
(CFIndex)strlen(bodydata));
if ( body == NULL )
{
fprintf(stderr, "CFDataCreate returned NULL");
goto Bail;
}

CFHTTPMessageSetBody( messageRef, body);
sprintf(szBoundary, "multipart/form-data; boundary=%s\r\n",
mytransfer.m_Boundary);
CFStringRef MyBoundary;
MyBoundary = CFStringCreateWithFormat( kCFAllocatorDefault, NULL,
CFSTR( "%s" ), szBoundary );
CFStringRef HeaderBoundary;
HeaderBoundary = CFStringCreateWithFormat( kCFAllocatorDefault, NULL,
CFSTR( "%s" ), "Content-Type" );
CFHTTPMessageSetHeaderFieldValue( messageRef, HeaderBoundary,
MyBoundary );
// Create the stream for the request.
readStreamRef = CFReadStreamCreateForHTTPRequest( kCFAllocatorDefault,
messageRef );
if ( readStreamRef == NULL )
{
fprintf(stderr, "CFReadStreamCreateForHTTPRequest returned NULL");
goto Bail;
}

CFReadStreamSetProperty(readStreamRef,
kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue);
CFReadStreamSetProperty(readStreamRef,
kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanFalse);
if ( CFReadStreamOpen(readStreamRef))
.
.
END NEXT QUOTE

When I run this code I do not get proper answers. To see what's wrong I run
a sniffer (ettercap) the sniffer shows that the header part is sent to the
server, then the server reponds with "HTTP/1.1 400 Bad request", and then my
code simply continues with sending the message body.
To me it seems that header and body should be sent in 1 transfer instead of
being split in two parts.
Does anyone have an idea why this happens?

BTW Dave Camp warned me about the abundant use of the "sprintf" command and
its dangers.
I'm pretty sure that is not the problem I'm facing here so I left the
example exactly as in my post to the printing list.

Regards,

Hans Loonen
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: why is my download request using HTTP POST is split in header and body ?
      • From: Jeremy Wyld <email@hidden>
    • Re: why is my download request using HTTP POST is split in header and body ?
      • From: Becky Willrich <email@hidden>
    • Re: why is my download request using HTTP POST is split in header and body ?
      • From: Becky Willrich <email@hidden>
  • Prev by Date: Modem connect speed not always available?
  • Next by Date: Re: why is my download request using HTTP POST is split in header and body ?
  • Previous by thread: Modem connect speed not always available?
  • Next by thread: Re: why is my download request using HTTP POST is split in header and body ?
  • Index(es):
    • Date
    • Thread