/*
* Created on
* Copyright
*
*/
package net
import java
import mons
/**
* @author YangHua
*/
public class MyClient {
/**
*的到Http請求結果
* @param url請求地址
* @param parms請求參數
* @return
*/
public byte[] getBody(String url
byte[] body=null;
//構造HttpClient的實例
HttpClient httpClient = new HttpClient();
//創建GET方法的實例
PostMethod postMethod = new PostMethod(url);
//填入各個表單域的值
NameValuePair[] data = new NameValuePair[parms
int i=
while (it
i++;
}
//將表單的值放入postMethod中
postMethod
try {
//執行postMethod
int statusCode = (postMethod); // HttpClient對於要求接受後繼服務的請求
//
if (statusCode == HttpStatus
//從頭中取出轉向的地址
Header locationHeader = postMethod
String location = null;
if (locationHeader != null) { location = locationHeader
} else {
System
}
}
body = postMethod
} catch (Exception e) {
e
}
return body;
}
public static void main(String[] args) {
String url=
Map parms=new HashMap();
MyClient client=new MyClient();
String result=new String(client
}
}
出處
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25989.html