我想知道如何通过调用HTTP方法Apache HttpClient来为Java编写PUT curl来为我做这个。
curl -X PUT username:passowrd http://localhost:80/api/cleint_id/include/id
我可以在java中轻松获取curl所以它显示所有id和client-is但是我坚持使用PUT curl将id包含到client_id中。我可以激发哪些想法或类似的工作?
由于
答案 0 :(得分:0)
你有没有理由不使用HttpPut http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/methods/HttpPut.html,因为你正在使用HttpClient?
Apache HttpComponents提供了客户端身份验证的示例。见http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientAuthentication.java
使用HttpPut调整它,你就完成了。
答案 1 :(得分:0)
您可以使用Apache HTTPClient,请参阅http://hc.apache.org/httpclient-3.x 并使用NameValuePair进行身份验证。
像这样HttpClient httpclient = new HttpClient();
PostMethod httppost = new PostMethod('your url');
NameValuePair[] data = [new NameValuePair("email", username),new NameValuePair("password", password)];
httppost.setRequestBody(data)
httpclient.executeMethod(httppost);
希望这有帮助