81,092
社区成员
发帖
与我相关
我的任务
分享
public void postOne(String url, Object task)
{
try
{
HttpPost httpost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("appID", task.getAppID()));
params.add(new BasicNameValuePair("cpID", task.getCpID().toString()));
params.add(new BasicNameValuePair("appToken", task.getAppToken()));
params.add(new BasicNameValuePair("price", task.getPrice().toString()));
params.add(new BasicNameValuePair("receipt", task.getReceipt()));
params.add(new BasicNameValuePair("userDeviceID", task.getUserDeviceID()));
httpost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse remoteResponse = this.httpClient.execute(httpost);
int responseState = remoteResponse.getStatusLine().getStatusCode();
if (HttpStatus.SC_OK == responseState)
{
// 请求成功
HttpEntity responseEntity = remoteResponse.getEntity();
if (responseEntity != null)
{// 返回信息
String strEntity = EntityUtils.toString(responseEntity, HTTP.UTF_8);
System.out.println(strEntity);
}
}
} catch (Exception e)
{
e.printStackTrace();
}
}
给你个简单的示例