[Servlet] how to send a stream to servlet doPost

G

Guest

Hi all:

I need to send a stream to servle doPost, Now I use
HttpURLConnection to call.

same times is work well, but same times is not work,

the simple code:

urlCach = new URL("http://192.168.0.88:8080/servlet/SMS");
urlconCach = (HttpURLConnection)urlCach.openConnection();
urlconCach.setDoOutput(true);
urlconCach.setRequestMethod("POST");
urlconCach.setUseCaches(false);
urlconCach.setDefaultUseCaches(false);

CachWriter = new OutputStreamWriter(urlconCach.getOutputStream(),
"GB2312");
CachWriter.write("same xml string");
CachWriter.flush();
CachWriter.close();


urlconCach.getResponseMessage();
urlconCach.disconnect();
 
M

Manish Pandit

Hi all:

I need to send a stream to servle doPost, Now I use
HttpURLConnection to call.

same times is work well, but same times is not work,

the simple code:

urlCach = new URL("http://192.168.0.88:8080/servlet/SMS");
urlconCach = (HttpURLConnection)urlCach.openConnection();
urlconCach.setDoOutput(true);
urlconCach.setRequestMethod("POST");
urlconCach.setUseCaches(false);
urlconCach.setDefaultUseCaches(false);

CachWriter = new OutputStreamWriter(urlconCach.getOutputStream(),
"GB2312");
CachWriter.write("same xml string");
CachWriter.flush();
CachWriter.close();

urlconCach.getResponseMessage();
urlconCach.disconnect();

Is there any change that causes it to fail, like ASCII vs. binary
data, large vs. small data, browser difference? May be you need to set
the request content type and/or the size. Please provide details on
the cases where it fails vs. passes. If it fails sporadically for the
same data, then it could even be a spotty connection. Also, you can
check and print out the responseCode as well as the response message
(which you are retrieving in the 2nd last line). It might carry some
information too (500?). Check the webserver/container log for any
exceptions or HTTP error codes as well.

-cheers,
Manish
 
G

Guest

Is there any change that causes it to fail, like ASCII vs. binary
data, large vs. small data, browser difference? May be you need to set
the request content type and/or the size. Please provide details on
the cases where it fails vs. passes. If it fails sporadically for the
same data, then it could even be a spotty connection. Also, you can
check and print out the responseCode as well as the response message
(which you are retrieving in the 2nd last line). It might carry some
information too (500?). Check the webserver/container log for any
exceptions or HTTP error codes as well.

-cheers,
Manish

It's two different system, One is java application,other is
servlet. use java send a string(xml file < 1M) to servlet, servlet
find loacle file, return a string(xml file < 1m) .it's base Http
socket.

When I get the response code, it's 500.

Thanks
 
G

GArlington

It's two different system, One is java application,other is
servlet. use java send a string(xml file < 1M) to servlet, servlet
find loacle file, return a string(xml file < 1m) .it's base Http
socket.

When I get the response code, it's 500.

Thanks

Are you trying to say that there are two separate systems
communication with each other (i.e. java application sending requests
to servlet, servlet sending responses to java application), or are you
trying to send the same request to two different systems - one with
servlet and another with java application?
If your case is option 1)java application sending requests to servlet,
servlet sending responses to java application
then you still did not show the differences between your requests or
the data that is being processed by servlet. Maybe the file it is
trying to process causes the error (500 = server [servlet run-time]
error).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top