我现在想用HttpURLConnection传一个参数到服务端,
服务端通过request.getparameter("param")来获取到这个参数但是,不能把参数放在URL后面:比如http://xxxx?param=aaaaa,不能这样传参看网上的例子,用post传参,是把参数放在正文里面
String content = " param= "
+ URLEncoder.encode(" a fat man ", " utf-8 ");
// DataOutputStream.writeBytes将字符串中的16位的 unicode字符以8位的字符形式写道流里面
out.writeBytes(content); 但是,我的content要传的是一个xml文件流。 Writer writer = new OutputStreamWriter(out);
// 发送soap消息到指定地址
writer.write(soapMsg); //soapMsg是xml文件内容请问:在客户端如何写,才能把这个参数传到服务端,并用request.getparameter获取到呢?
服务端通过request.getparameter("param")来获取到这个参数但是,不能把参数放在URL后面:比如http://xxxx?param=aaaaa,不能这样传参看网上的例子,用post传参,是把参数放在正文里面
String content = " param= "
+ URLEncoder.encode(" a fat man ", " utf-8 ");
// DataOutputStream.writeBytes将字符串中的16位的 unicode字符以8位的字符形式写道流里面
out.writeBytes(content); 但是,我的content要传的是一个xml文件流。 Writer writer = new OutputStreamWriter(out);
// 发送soap消息到指定地址
writer.write(soapMsg); //soapMsg是xml文件内容请问:在客户端如何写,才能把这个参数传到服务端,并用request.getparameter获取到呢?
method.setParameter("name_c", username);
method.setParameter("codestr", codestr);
method.setParameter("RegAnswer", "11");
比如getRequestPropertyhttp://www.cnblogs.com/linjiqin/archive/2011/09/19/2181634.html
我这个客户端是发送的soap消息,是用httpclient代替HttpURLConnection吗?
能不能详细说一下
这篇文章里,
1、向服务器发送get请求 这个是可以实现,但是我不想用get请求2、向服务器发送post请求
outStream.write(data);
我的代码里,这个data是一个xml文件,这个该怎么搞?
如果想要用getter方法接,那試試把這個xml內容作為參數值寫入并傳遞
urlConn.setDoOutput(true);urlConn.setDoInput(true);urlConn.setUseCaches(false);
post发送如下:
DataOutputStream out = new DataOutputStream(urlConn.getOutputStream());
// 正文,正文内容其实跟get的URL中'?'后的参数字符串一致
String content = "firstname=" + URLEncoder.encode("中国共产党", "utf-8");
out.writeBytes(content);
out.flush();
out.close();