私は現在、bitbucketの問題であるRESTfulAPI用のライブラリを開発しています。私は順調に進歩しました。次に、 HTTPPUTリクエストを要求する問題の更新のセクションに取り組みます。
HTTPエラーコードが原因でスタックしています411 Length Required
。少しグーグルした後、次のコード例を見つけました。
// CORRECT: get a UTF-8 encoded byte array from the response
// String and set the content-length to the length of the
// resulting byte array.
String response = [insert XML with UTF-8 characters here];
byte[] responseBytes;
try {
responseBytes = response.getBytes("UTF-8");
}
catch ( UnsupportedEncodingException e ) {
System.err.print("My computer hates UTF-8");
}
this.contentLength_ = responseBytes.length;
今私の質問:正確に測定されるものは何ですか?
- クエリ文字列
- urlencodedクエリ文字列
- パラメータの値のみ...??
そしてconnection.setRequestProperty("Content-Length", String.valueOf(<mycomputedInt>));
、コンテンツの長さ属性を設定する適切な方法はありますか?
例をいただければ幸いです。前もって感謝します。
編集:
たとえば、bitbucketwikiエントリの次のcurlの例を使用して計算を説明できます。
curl -X PUT -d "content=Updated%20Content" \
https://api.bitbucket.org/1.0/repositories/sarahmaddox/sarahmaddox/issues/1/