Lei,

Thanks for the explanation. I will shortly explain what your code is actually doing. It generates a request looking like this:

----
POST ShippingAPITest.dll HTTP/1.1
Host: testing.shippingapis.com
Content-Type: application/x-www-form-urlencoded
Content-Length: ....

API=GlobalExpressMailLabelCertify&XML=<%3Fxml ...%3F>%0A<somedata>...
----

I don't think it is what you intended to do. You probably want to emulate a file upload like in the HTML form:
---
<form action="ShippingAPITest.dll" method="POST">
<input type="hidden" name="API" value="GlobalExpressMailLabelCertify">
<input type="file" name="XML">
</form>
---


You need to make a request in "multipart/form-data" format:
---
POST /cgi-bin/upload.pl HTTP/1.1
Content-Type: multipart/form-data; boundary=--------------------------
+-7d03135102b8
Host: deville
Content-Length: ....

-----------------------------7d03135102b8
Content-Disposition: form-data; name="file"; filename="my.xml"
Content-Type: text/xml

<?xml version="1.0" ?>
<mydata>
</mydata>

-----------------------------7d03135102b8
Content-Disposition: form-data; name="API"

GlobalExpressMailLabelCertify
-----------------------------7d03135102b8--
---

The Multipart utilities will do exactly that for you. Have a look at MultipartFileUploadApp in the examples. Your code will be along the lines of:

File targetFile = new File(XML_REQUEST_FILE_NAME);
PostMethod filePost = new PostMethod(SHIPPING_URI);
filePost.getParams().setBooleanParameter(
  HttpMethodParams.USE_EXPECT_CONTINUE, true
);

Part[] parts = {
    new StringPart("API", API_NAME, "US-ASCII"),
    new FilePart("XML", targetFile)
};
filePost.setRequestEntity(
    new MultipartRequestEntity(parts, filePost.getParams())
);
HttpClient client = new HttpClient();
int status = client.executeMethod(filePost);


HTH

Ortwin Gl�ck

Lei Cao wrote:
Hi Ortwin,
I am sending an encoded xml file to USPS shipping test server. The user name and password are in the xml file. I expect that the USPS test server would send me back a xml file with information I want.


The status code that I received is 200, which means the request has been 
processed successfully.

But I got the following in my console:
 org.apache.commons.httpclient.HttpMethodBase readResponse
 INFO: Discarding unexpected response: HTTP/1.1 100 Continue

And I also got the error message from the USPS test server, says that I have 
not sent the user name correctly. I have already checked the user name and the 
password with them, and they are both correct. The USPS shipping developer team 
checked the unencoded xml file, and the file is correct. Actually it is a 
standard sample file, only with different user name and password. So I am 
wondering whether the encoded xml file has been sent correctly.

Best regard

Lei Cao

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to