Hi Markus,
Give Apache HttpComponents a try ->
http://hc.apache.org/httpcomponents-client-ga/index.html
You'll be much happier.
Regards,
Bogdan Zlatanov
On 8 Mar 2013, at 18:11, Markus Ruggiero wrote:
> Hi,
>
> I have a component that generates some XML data. Works fine. Now I need to
> upload that XML data via a POST to some remote server. How would I do that?
> Here is the code I use, but somehow the remote server chokes with the
> contents I send it. When I let the frameworks return the XML to my browser
> everything looks good. I suspect that my packaging the XML into a request
> somehow corrupts it. Or maybe there are some headers missing.
>
>
> This is a direct action that returns what I want:
>
> try {
> Product product = (Product)products.objectAtIndex( 0 ); //
> Product is an EO
> TransferXMLGenerator generator =
> (TransferXMLGenerator)pageWithName( TransferXMLGenerator.class);
> generator.setProduct( product );
>
> }
> catch (Exception e) {
> System.out.println(e.getMessage());
> }
>
> return generator;
>
>
> And this is the code that generates the XML and then directly uploads it to
> the remote host:
>
> TransferXMLGenerator generator = (TransferXMLGenerator)pageWithName(
> TransferXMLGenerator.class);
> generator.setProduct( product );
> WOResponse generatorResponse = generator.generateResponse();
> NSData xml = generatorResponse.content();
> // *** I assume that XML now is the very same as is returned to the browser
> in the case of the direct action above
> // *** This assumption might be wrong
> // send XML data to front end
> Application application = (Application)Application.application();
> WORequest request = new WORequest("POST", application.mondPath(),
> "HTTP/1.0", null, xml, null);
> BASE64Encoder enc = new BASE64Encoder();
> String authHeaderContent = "Basic " + enc.encode((mondUser +":" +
> mondPasswd).getBytes());
> request.setHeader( authHeaderContent, "Authorization" );
> request.setHeader(application.mondHost(), "host");
> request.setHeader("Java/1.6", "user-agent");
>
> WOHTTPConnection connection = new
> WOHTTPConnection(application.mondHost(), application.mondPort());
> messages.append( "\nConnection = " + connection.toString());
>
> if (connection.sendRequest( request )) {
> WOResponse frontendResponse = connection.readResponse();
>
> The problem is that when I send the direct action generated XML by hand,
> outside of my app, with the help of an upload tool (custom tool, not under my
> control, no source available), the remote server is happy, whereas when I
> send it via the second part above, directly from my app, the remote server
> accepts my data but then complains that there are some structural problems
> with the data. So, the communication works, but obviously the data sent
> differs in those two cases.
>
> Any idea? Is WOHTTPConnection and WORequest the right thing to use here? Am I
> using it right?
>
> Thanks for any help.
> ---markus---
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/bogdan.zlatanov%40gmail.com
>
> This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]