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

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

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

開(kāi)通VIP
HTTP

1,post-Body流和post參數,以下客戶(hù)端代碼和服務(wù)端代碼可共用

  1. 客戶(hù)端代碼
  2. /**
  3. * post 方法
  4. * 拋送給EDI
  5. * @param url http://127.0.0.1:9003/api/edi/csm/csmReturnSubConBody?customerId=Fotile_CSM&api=csmreturnsub_confirm&id=6006
  6. * @param jsonParam xml報文結構
  7. * @return
  8. */
  9. String httpPost45(String url, String jsonParam) {
  10. //url?后面的即為post parmas 參數,bodu 放在數據流中進(jìn)行傳輸
  11. CloseableHttpClient httpclient = HttpClients.createDefault()
  12. // HttpGet httpGet = new HttpGet(url)
  13. HttpPost post=new HttpPost(url)
  14. //httpClient 4.5版本的超時(shí)參數配置
  15. RequestConfig requestConfig = RequestConfig.custom()
  16. .setConnectTimeout(50000).setConnectionRequestTimeout(50000)
  17. .setSocketTimeout(50000).build()
  18. post.setConfig(requestConfig)
  19. //往BODY里填充數據主體
  20. StringEntity entitys=new StringEntity(jsonParam.toString(), "utf-8")
  21. entitys.setContentEncoding("UTF-8")
  22. entitys.setContentType("application/xml")
  23. post.setEntity(entitys)
  24. HttpResponse response = httpclient.execute(post)
  25. // System.out.println("得到的結果:" + response.getStatusLine())//得到請求結果
  26. String str = EntityUtils.toString(response.getEntity())//得到請求回來(lái)的數據
  27. return str
  28. }

客戶(hù)端代碼二=========================================


如果只是簡(jiǎn)單拼接進(jìn)url是行不通的,因為我們都知道URLEncoder,對url字符集編碼設置,所以需要對所有的值進(jìn)行字符集編碼設置,最終我們封裝成了如下post方法支持url拼接入相應的請求參數:

POST_URL:請求url
urlParam:如上需要封裝進(jìn)url的參數
body:普通需要傳遞的參數

  1. public static String httpURLConnectionPOST (String POST_URL,Map<String, String> urlParam,String body) {
  2. CloseableHttpResponse response = null;
  3. try {
  4. RequestConfig defaultRequestConfig = RequestConfig.custom()
  5. .setSocketTimeout(6000)
  6. .setConnectTimeout(6000)
  7. .setConnectionRequestTimeout(6000)
  8. .build();
  9.         //httpclient
  10. CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
  11. // HttpPost httpPost = new HttpPost(POST_URL);
  12. StringBuilder param=new StringBuilder("");
  13. //將要拼接的參數urlencode
  14. for (String key:urlParam.keySet()){
  15. param.append(key + "=" + URLEncoder.encode(urlParam.get(key), "UTF-8") + "&");
  16. }
  17. //pingjie
  18. HttpPost httpPost = new HttpPost(POST_URL+param.toString());
  19. //請求參數設置
  20. if(com.sf.ccsp.common.util.StringUtils.isNotEmpty(body)){
  21. StringEntity entity=new StringEntity(body, ContentType.APPLICATION_JSON);
  22. httpPost.setEntity(entity);
  23. }
  24. response = httpclient.execute(httpPost);
  25. HttpEntity entity = response.getEntity();
  26. return EntityUtils.toString(entity, "UTF-8");
  27. } catch (UnsupportedEncodingException e) {
  28. logger.error(e.getMessage(), e);
  29. } catch (ClientProtocolException e) {
  30. logger.error(e.getMessage(), e);
  31. } catch (IOException e) {
  32. logger.error(e.getMessage(), e);
  33. } catch (Exception e){
  34. System.out.println(e);
  35. }finally {
  36. if (response != null) {
  37. try {
  38. response.close();
  39. } catch (IOException e) {
  40. logger.error(e.getMessage(), e);
  41. }
  42. }
  43. }
  44. return null;
  45. }

服務(wù)端代碼

  1. @ResponseBody
  2. @RequestMapping(value = "csmReturnSubConBody", method = RequestMethod.POST, produces = "application/xml")
  3. ResponseMessage csmReturnSubConBody(HttpServletRequest request, HttpServletResponse response,
  4. @RequestParam Map<String, String> params) {
  5. //params為客戶(hù)端URL?后面的參數集,同理,也可以將bodu放到參數集里,進(jìn)行傳輸
  6. CustomerInfo customerInfo = erpSetting.getCustomerInfo(params.customerId as String)
  7. if (!customerInfo) return
  8. ApiInfo apiInfo = erpSetting.getApiInfo(customerInfo, params.api as String)
  9. if (!apiInfo) return
  10. String body = readBody(request)//這里去解析post流里的body數據
  11. ResponseMessage rsp = csmSvc.convertBodyAndSendErpRetu(apiInfo, customerInfo, body, "xml", params.id as Object, null)
  12. return rsp
  13. }
  14. 對于post參數流,服務(wù)端,可以這樣取值
  15. String body = params.keySet()[0] + "=" + params[params.keySet()[0]].toString()
  16. params.keySet()[0]得到key
  17. params[params.keySet()[0]].toString()得到第一個(gè)key的value

OLY電子標簽項目

2 httpPost form 表單提交 application/x-www-form-urlencoded

  1. import com.ittx.wms.api.service.ToolApiService
  2. import org.apache.http.Header
  3. import org.apache.http.HeaderElement
  4. import org.apache.http.HttpEntity
  5. import org.apache.http.ParseException
  6. import org.apache.http.client.entity.UrlEncodedFormEntity
  7. import org.apache.http.client.methods.CloseableHttpResponse
  8. import org.apache.http.client.methods.HttpPost
  9. import org.apache.http.impl.client.CloseableHttpClient
  10. import org.apache.http.impl.client.HttpClientBuilder
  11. import org.apache.http.message.BasicNameValuePair
  12. import org.apache.http.util.EntityUtils
  13. import org.springframework.beans.factory.annotation.Autowired
  14. import java.nio.charset.StandardCharsets
  15. /**
  16. *
  17. * Create by administrator 2021/4/12/0012 17:48
  18. *
  19. **/
  20. class Test {
  21. @Autowired
  22. ToolApiService taSvc
  23. public static void main(String[] args) {
  24. doPost("1", "1")
  25. }
  26. public static String doPost(String strUrl, String content) {
  27. CloseableHttpClient httpClient = HttpClientBuilder.create().build()
  28. HttpPost httpPost = new HttpPost("http://yun.zhuzhufanli.com/mini/select/");
  29. CloseableHttpResponse response = null;
  30. try {
  31. httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded")
  32. List<BasicNameValuePair> param = new ArrayList<>()
  33. param.add(new BasicNameValuePair("appid", "160290"))
  34. param.add(new BasicNameValuePair("outerid", "7649974ED0D8499B"))
  35. param.add(new BasicNameValuePair("pageno", "1"))
  36. param.add(new BasicNameValuePair("taskname", "J210412_151338685"))
  37. UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(param, StandardCharsets.UTF_8)
  38. httpPost.setEntity(formEntity)
  39. response = httpClient.execute(httpPost)
  40. HttpEntity responseEntity = response.getEntity()
  41. println "HTTP響應狀態(tài)為:" + response.getStatusLine()
  42. if (responseEntity != null) {
  43. println "HTTP響應內容長(cháng)度為:" + responseEntity.getContentLength()
  44. String responseStr = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8)
  45. println "HTTP響應內容為:" + responseStr
  46. return responseStr
  47. }
  48. } catch (IOException e) {
  49. e.printStackTrace()
  50. } finally {
  51. try {
  52. if (httpClient != null) {
  53. httpClient.close()
  54. }
  55. if (response != null) {
  56. response.close()
  57. }
  58. } catch (IOException e) {
  59. e.printStackTrace()
  60. }
  61. }
  62. }
  63. }
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
spring集成httpclient連接池配置
HttpClient-aaaaa
springboot 整合httpclient【面試+工作】
HttpClient工具類(lèi)
關(guān)于調用接口 Connection reset 問(wèn)題(使用代理調接口)
JAVA利用HttpClient進(jìn)行POST請求(HTTPS)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

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