Cocoa: How do I send/receive XML within a HTTP connect?
Cocoa: How do I send/receive XML within a HTTP connect?
- Subject: Cocoa: How do I send/receive XML within a HTTP connect?
- From: email@hidden
- Date: Fri, 16 May 2008 10:59:25 -0700 (PDT)
Hello, I'm having trouble determining the best path to follow.
Here's the schema in a nutshell:
[Mac <---- XML/SOAP -----> Server]
.. where an HTTP Post connection is created and a post/reply is synchronously generated.
I want to use Cocoa to do the equivalent in Java:
StreamConnection xmlstream = null;
HttpConnection connection = null;
xmlstream = (StreamConnection)Connector.open(SOAP_SERVER_URL + ";deviceside=false",Connector.READ_WRITE,true);
...
OutputStream out = connection.openOutputStream(); // HttpConnection class.
out.write(xmlreq.getBytes()); // Note: 'xmlreq' is type String.
...
// ---- Get Response -----
// Get the connection status
status = connection.getResponseCode(); // HttpConnection class.
------------------------------
Specifically, I need to:
1) Open a read/write connection to a WSDL Soap server. <-- using NSURLConnection?
2) Change Request Properties & Methods to reflect a POST connection. <-- using NSMutableURLRequest?
3) Send a XML (SOAP envelope) to the Server; and <-- ? inside NSURLConnection?
4) Get a XML response. <-- via NSURLConnection?
This is a SYNCHRONOUS, HTTP (POST) connection.
====================
Here's my dilemma:
1) I thought about using the Core Foundation (CFNetworking) route:
// Java equivalent: connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
CFHTTPMessageSetHeaderFieldValue(myRequest,CFSTR("User-Agent"), CFSTR("Apple iPhone"));
CFHTTPMessageSetHeaderFieldValue(myRequest,CFSTR("Content-Type"), CFSTR("text/xml; charset=utf-8"));
CFHTTPMessageSetHeaderFieldValue(myRequest,CFSTR("Accept"), CFSTR("text/html"));
But I don't know how to Synchronously Send/Receive as shown in the Java code, above.
2) If possible, I prefer to use the higher-level NSNetworking scheme: via NSMutableURLRequest.
I can modify the request to be POST and I think I can modify the header for the Content-Type, etc.
Do I use NSURLConnection to actually TRANSMIT & RECEIVE XML data to the Server like this?
serverData = [NSURLConnection sendSynchronousRequest:theRequest
returningResponse:serverResponse
error:myError];
3) Then, how do I flush(), close() this connection?
4) or... must I try the CF route?
Regards,
Ric.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden