永发信息网

httpClient中post的参数设置

答案:1  悬赏:10  手机版
解决时间 2021-05-18 21:49
  • 提问者网友:王者佥
  • 2021-05-18 02:34

http header:
Set-Cookie:ONE_VER=1_0;
http body:
<validateticket>
<ticket>{ the One-Time Ticket from ASUS Access}</ticket>
<validateticket>

httpclient要将这些参数发送出去,希望高手能指点一下,最好能写出源码,post请求!!万分感谢!!!

最佳答案
  • 五星知识达人网友:青尢
  • 2021-05-18 02:48

private static void post() throws IOException{
URL url = new URL(" http://www.baidu.com");// 提交地址
    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); 
    httpURLConnection.setDoOutput(true);// 打开写入属性 
    httpURLConnection.setDoInput(true);// 打开读取属性 
    httpURLConnection.setRequestMethod("POST");// 设置提交方法 
    httpURLConnection.setRequestProperty("Content-Type","text/xml;charset=UTF-8");//
httpURLConnection.setRequestProperty("SOAPAction", " http://WebXml.com.cn/getWeatherbyCityName");
    httpURLConnection.setRequestProperty("User-Agent", "Jakarta Commons-HttpClient/3.1");
    httpURLConnection.setConnectTimeout(50000);// 连接超时时间 
    httpURLConnection.setReadTimeout(50000); 
    httpURLConnection.connect(); 
   
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(httpURLConnection.getOutputStream())); 
    out.write("name=1&pwd=2");
    out.flush(); 
    out.close(); 
 
    //读取post之后的返回值 
    BufferedReader in = new BufferedReader(new InputStreamReader((InputStream) httpURLConnection.getInputStream(),"UTF-8")); 
    String line = null; 
    StringBuilder sb = new StringBuilder(); 
    while ((line = in.readLine()) != null) { 
    sb.append(line); 
    } 
    in.close(); 
    System.out.println("client:" + sb.toString());    
    httpURLConnection.disconnect();//断开连接 
 }


不行 贴出你的联系方式

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯