gpt4 book ai didi

servlets - Java 中的 HTTP post 不会在服务器端发布

转载 作者:行者123 更新时间:2023-12-02 03:35:14 26 4
gpt4 key购买 nike

<分区>

我正在尝试使用 HTTP post 发布数据,但我无法在另一端(服务器)看到数据。当我运行程序时,我得到一个响应代码 200(成功),但是当我交叉检查时,在另一端没有发现任何数据

private void sendPost() throws Exception {

String url = "https://example.com/post/index.php";
URL obj = new URL(url);

HttpsURLConnection con = (HttpsURLConnection)obj.openConnection();


//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("charset", "utf-8");



String urlParameters = "username=userpv&password=pvpwd&admin_username=&admin_password=&action=add&requisition_number=403555&return_url=&error_url=www.some.com&error_format=1";

// urlParameters string is very long

con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();

int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));


String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();

//print result
//System.out.println(response.toString());

}

谁能告诉我我的代码有什么问题?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com