Java HTTPPost请求返回HTTP错误500 [关闭]

问题描述 投票:-1回答:1
private HttpPost getRequest() {
    HttpPost httpRequest = null;

    postParameter();

    String queryString = "";
    Set<Entry<String, String>> getPairs = this.parameterMap.entrySet();
    for (Entry<String, String> entry : getPairs) {
        try {
            queryString += URLEncoder.encode(entry.getKey(), this.CHARSET) + "=" + URLEncoder.encode(entry.getValue(), this.CHARSET) + "&";
        } catch (UnsupportedEncodingException e) {
        }
    }
    if (!queryString.isEmpty()) {
        queryString = "?" + queryString;
    }

    httpRequest = new HttpPost("http://mydomainname.com/java_test.php");
    String user_password = username+":"+password;
    byte[] Author = Base64.getEncoder().encode(user_password.getBytes());
    String Authorization = null;
    try {
        Authorization = new String(Author, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
    }
    String partnerID ="XXXXXX";     
    httpRequest.setHeader("Authorization",Authorization);
    httpRequest.setHeader("PartnerId",partnerID);       
    httpRequest.addHeader(HttpHeaders.CONTENT_TYPE,"application/json");
    httpRequest.addHeader(HttpHeaders.ACCEPT,"application/json");               
    List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>();
    Set<Entry<String, String>> postPairs = this.postParametersMap.entrySet();
    for(Entry<String, String> entry : postPairs) {
        BasicNameValuePair pair = new BasicNameValuePair(entry.getKey(),
                entry.getValue());
        nameValuePairs.add(pair);
    }

    UrlEncodedFormEntity parameters = null;
    try {
        parameters = new UrlEncodedFormEntity(nameValuePairs, this.CHARSET);
    } catch (UnsupportedEncodingException e) {
    }

    httpRequest.setEntity(parameters);
    return httpRequest;
}

HTTPS POST ERROR 500上面的请求,这是一个简单的HTTP客户端,带有JSON数组的CUSTOM HEADER(授权,partnerid,类型,接受)。

相同的代码在其他主机JAVA 7上功能,但不能在JAVA 11上运行。

java json eclipse http http-status-code-500
1个回答
1
投票

代码500是服务器错误。

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500

超文本传输​​协议(HTTP)500内部服务器错误服务器错误响应代码表示服务器遇到意外情况,导致服务器无法完成请求。

在java方面没有问题。

© www.soinside.com 2019 - 2024. All rights reserved.