package com.http.client;
import org.apache.commons.digester.Digester;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TopUpClient {
private String url = "http://10.0.3.65:8081/web/api/topup/";
private static String key = MD5
.encrypt("civony_{00100-15222-222-55220}");
private HttpClient client;
private PostMethod post;
private String orderid;
private String money;
private String aumont;
private String payaccount;
private String paytype;
private String sign;
@Before
public void init() {
client = new HttpClient();
post = new PostMethod(url);
orderid = "111222323334";
money = "200.32";
aumont = "1000";
payaccount = "5dsdd";
paytype = "1";
sign = MD5.encrypt(orderid + money + aumont + payaccount + paytype
+ key);
}
@Test
public void rightRequest() {
try {
NameValuePair[] data = { new NameValuePair("money", money),
new NameValuePair("orderid", orderid),
new NameValuePair("aumont", aumont),
new NameValuePair("payaccount", payaccount),
new NameValuePair("paytype", paytype),
new NameValuePair("sign", sign) };
post.setRequestBody(data);
int statusCode = client.executeMethod(post);
System.out.println(statusCode);
String result = post.getResponseBodyAsString();
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
@After
public void release(){
if(post!=null){
post.releaseConnection();
}
}
}
httpClient应用
最新推荐文章于 2024-09-12 09:04:49 发布