C sharp的简易Http库有一种将数据发布到url的方法,
var customer = new Customer();
customer.Name = "Joe";
customer.Email = "joe@smith.com";
var http = new HttpClient();
http.Post("url", customer, HttpContentTypes.ApplicationJson);
寻找一些库来将数据发布到Java的URL。
答案 0 :(得分:0)
Jersey是一个很棒的免费API,用于对网址POST
和GET
进行操作。
MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
formParams.add("requestXML",requestXML);
formParams.add("version","1");
WebResource webResource = Client.create().resource("http://myurl.org/");
String response = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(String.class, formParams);
答案 1 :(得分:0)
您可以使用Apache的HTTPClient在Java中创建基本的HTTP
操作。
例如,POST
看起来像这样:
HttpPost httpPost = new HttpPost("http://some-web-site");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("name", "Joe"));
nvps.add(new BasicNameValuePair("email", "joe@smith.com"));
httPost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity result = response.getEntity();