gpt4 book ai didi

java - 无法使用 Http put 方法将数据发送到 URL

转载 作者:行者123 更新时间:2023-12-01 15:37:55 25 4
gpt4 key购买 nike

我无法使用 put 方法将数据发送到特定链接。请在下面找到代码。如果我需要进行任何更改,请告诉我

public class test {
private static String url = "http://semldvw0728.google.net/.svc/web/testrequests/";
private static String urlconnection;

public static void main(String[] args) throws IOException {

StringBuffer xmlString = new StringBuffer();

xmlString.append("<TestRequest>");
xmlString.append("<DateRequested>2011-12-20</DateRequested>");
xmlString.append("<DemCapID>893467</DemCapID>");
xmlString.append("<DemCapVersion>1</DemCapVersion>");
xmlString.append("<IBIS_ID>13530</IBIS_ID>");
xmlString.append("<ProjectName>LTS</ProjectName>");
xmlString.append("<RequestedBy>ktmq331</RequestedBy>");
xmlString.append("<SampleNumber>SN1033645061</SampleNumber>");
xmlString.append("<Status>Sample Ordered</Status>");
xmlString.append("</TestRequest>");

System.out.println("xmlString :" + xmlString.toString());
url = url + 893467;
System.out.println("URL : " + url);

try {
System.out.println("URL : " + url);
HttpClient client = new HttpClient();
PutMethod putMethod = new PutMethod(url);
client.setConnectionTimeout(8000);
putMethod.setRequestBody(xmlString.toString());
System.out.println("statusLine>>>" + putMethod.getStatusLine());
System.out.println("statusLine>>>"+ putMethod.getResponseBodyAsString());
putMethod.releaseConnection();
} catch (Exception e) {
e.printStackTrace();
}
}

最佳答案

我认为您需要调用execute ,或者您可以使用您创建的 HttpClient 对象 call this .

因此,也许在为 putMethod 设置请求正文后添加此行...

client.executMethod(putMethod);

关于java - 无法使用 Http put 方法将数据发送到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8581586/

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