Closed GoogleCodeExporter closed 9 years ago
Try this:
InputStreamContent content = new InputStreamContent();
content.setByteArrayInput(new byte[0]);
content.type = "text/plain";
request.content = content;
Original comment by yan...@google.com
on 24 Feb 2011 at 3:52
[deleted comment]
Thank you for the answer.I tried the code,it seems still doesn't work correct.
my code like this:
public void list() throws IOException
{
HttpRequest request = transport.buildGetRequest();
request.setUrl("http://commondatastorage.googleapis.com");
InputStreamContent content = new InputStreamContent();
content.setByteArrayInput(new byte[0]);
content.type = "text/plain";
request.content = content;
request.headers.put("Date",Now());
try {
HttpResponse response = request.execute();
System.out.println(response.parseAsString());
}catch (HttpResponseException e){
System.out.println(e.response.parseAsString());
};
}
I use fiddle catch to package, include your code the Httpmethod is post
del the code httpmethod is correct :get.
I trace the code in the httprequest.class ,the httpmethod still is "get"
is there a point think content has a inputstream then set httpmethod to post?
by the way if not set content googlestoageauthorize doesn't work correct.
another silly question:how to parser the googlestorage error status,
I found the code in issue 9:
XmlHttpParser errorParser = new XmlHttpParser();
errorParser.contentType = "application/vnd.google.gdata.error+xml";
errorParser.namespaceDictionary = errorNamespaceDictionary;
transport.addParser(errorParser);
but errorNamespaceDictionary isn't valid.And doest is need to design a
errorstatus class to parser it?
Original comment by zcmk...@gmail.com
on 24 Feb 2011 at 1:43
There seems has a bug.I traced in httprequest.java:
HttpResponse response = new HttpResponse(transport,
lowLevelHttpRequest.execute());
before this lowLevelHttpRequest.connection.method is GET
after this lowLevelHttpRequest.connection.method is POST
Original comment by zcmk...@gmail.com
on 27 Feb 2011 at 8:14
[deleted comment]
In NetHttpRequest.java ,public LowLevelHttpResponse execute():
content.writeTo(connection.getOutputStream());
if you call connection.getOutputStream(),connection.method change from "GET" to
"POST";
since all GET content-length=0, I suggest the code to this:
if (content != null) {
connection.setDoOutput(true);
String contentType = content.getType();
if (contentType != null) {
addHeader("Content-Type", contentType);
}
String contentEncoding = content.getEncoding();
if (contentEncoding != null) {
addHeader("Content-Encoding", contentEncoding);
}
long contentLength = content.getLength();
if (contentLength >= 0) {
addHeader("Content-Length", Long.toString(contentLength));
}
if (contentLength > 0) {
connection.setDoOutput(true);
content.writeTo(connection.getOutputStream());
}
}
Original comment by zcmk...@gmail.com
on 14 Mar 2011 at 11:38
Need to try to reproduce it.
Original comment by yan...@google.com
on 22 Mar 2011 at 2:26
Taking a look at the JavaDoc for HttpURLConnection on Android:
http://developer.android.com/reference/java/net/HttpURLConnection.html
It says that calling setDoOutput(true) changes the method from GET to POST.
Original comment by yan...@google.com
on 5 Apr 2011 at 7:31
http://codereview.appspot.com/4354051/
Original comment by yan...@google.com
on 5 Apr 2011 at 7:53
Original comment by yan...@google.com
on 5 Apr 2011 at 7:56
Original issue reported on code.google.com by
zcmk...@gmail.com
on 24 Feb 2011 at 3:13