欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
使用HttpClient通過(guò)POST方式發(fā)送XML

以下是代碼的示例,目前還未真正測試過(guò)服務(wù)器端到底能不能接受到這次請求數據,只是簡(jiǎn)單觀(guān)察了下 TCP/IP Monitor, 后期會(huì )投入一定的時(shí)間繼續深入這套API組件.

IClient.java

package com.apt.client;

/**
* Constant Interface to define the normal Constant in this application

* @author Lv Pin

*/

public interface IClient {

     /**
      * The XML Header of every XML string
     */
      public String XML_HEADER = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
}

XMLClient.java

package com.apt.client;

import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

/**
* HTTP Client, to send data of XML type to Server. This is a demonstration of
* how to use HTTP Client API

* @author Lv Pin

*/
public class XMLClient {

  /**
    * HTTP Client Object,used HttpClient Class before(version 3.x),but now the
    * HttpClient is an interface
    */
   private DefaultHttpClient client;

  /**
     * Get XML String
     * 
     * @return XML-Formed string
   */
public String getXMLString() {
// A StringBuffer Object
  StringBuffer sb = new StringBuffer();
  sb.append(IClient.XML_HEADER);
  sb.append("<AastraIPPhoneInputScreen type=\"string\">");
  sb.append("<Title>Hello world!</Title>");
  sb.append("<Prompt>Enter value</Prompt>");
  sb.append("<URL>http://localhost/xmlserver/test.do</URL>");
  sb.append("<Parameter>value</Parameter>");
  sb.append("<Default></Default>");
  sb.append("</AastraIPPhoneInputScreen>");
// return to String Formed
  return sb.toString();
}

/**
  * Send a XML-Formed string to HTTP Server by post method
  * 
  * @param url
  *            the request URL string
  * @param xmlData
  *            XML-Formed string ,will not check whether this string is
  *            XML-Formed or not
  * @return the HTTP response status code ,like 200 represents OK,404 not
  *         found
  * @throws IOException
  * @throws ClientProtocolException
  */
public Integer sendXMLDataByPost(String url, String xmlData)
   throws ClientProtocolException, IOException {
  Integer statusCode = -1;
  if (client == null) {
   // Create HttpClient Object
   client = new DefaultHttpClient();
  }
// Send data by post method in HTTP protocol,use HttpPost instead of
  // PostMethod which was occurred in former version
  HttpPost post = new HttpPost(url);
// Construct a string entity
  StringEntity entity = new StringEntity(xmlData);
  // Set XML entity
  post.setEntity(entity);
  // Set content type of request header
  post.setHeader("Content-Type", "text/xml;charset=ISO-8859-1");
// Execute request and get the response
  HttpResponse response = client.execute(post);
  // Response Header - StatusLine - status code
  statusCode = response.getStatusLine().getStatusCode();
  return statusCode;
}

/**
  * Main method 
  * @param args
  * @throws IOException 
  * @throws ClientProtocolException 
  */
public static void main(String[] args) throws ClientProtocolException, IOException {
  XMLClient client = new XMLClient();
  Integer statusCode = client.sendXMLDataByPost("http://localhost:8081", client.getXMLString());
  if(statusCode==200){
   System.out.println("Request Success,Response Success!!!");
  }else{
   System.out.println("Response Code :"+statusCode);
  }
}
}


本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
通過(guò)HttpClient請求webService
Java 使用httpclient Post與cxf 發(fā)布的Webservice通信
JAVA版微信支付V3-完全版
HttpClient工具類(lèi)
Android封裝的http請求實(shí)用工具類(lèi)
HttpClient 4.0.1 請求特別慢的原因分析
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久