0

I connect a nginx http service by socket,i use java Language:

url:api.weibo.com/2/users/show.json

GET /2/users/show.json HTTP/1.1
Host: api.weibo.com
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
Cookie: PHPSESSID=uc67dtcb5r3orchgv0dgdd0f57; think_template=default

but it return:

HTTP/1.1 400 Bad Request
Server: Weibo
Date: Sat, 24 Jan 2015 10:07:33 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Api-Server-IP: 10.75.0.174
Vary: Accept-Encoding

60
{"error":"source paramter(appkey) is missing","error_code":10006,"request":"/2/users/show.json"}
0

i don't know what is the '60' and '0'

if i use HTTP/1.0 instand of HTTP/1.1,it return:

HTTP/1.1 400 Bad Request
Server: Weibo
Date: Sat, 24 Jan 2015 10:22:09 GMT
Content-Type: application/json;charset=UTF-8
Connection: close
Api-Server-IP: 10.75.5.92
Vary: Accept-Encoding

{"error":"source paramter(appkey) is missing","error_code":10006,"request":"/2/users/show.json"}

if i use socket connect iis or apache,all ok to use HTTP/1.1

Anybody can tell me why,and how to Solve?

Chris
  • 6,914
  • 5
  • 54
  • 80
cs x
  • 621
  • 2
  • 8
  • 23
  • possible duplicate of [Chunked http decoding in java?](http://stackoverflow.com/questions/3717640/chunked-http-decoding-in-java) – Joe Jan 24 '15 at 13:14

1 Answers1

0

The webservice returns the content in chunks, by first sending the length of the next chunk. It is using Chunked Transfer Encoding.

You are saying you can speak HTTP/1.1 with GET /2/users/show.json HTTP/1.1 and

All HTTP/1.1 applications MUST be able to receive and decode the "chunked" transfer-coding....

You could use something like the Apache HttpClient or some other Java HTTP client library to avoid implementing HTTP on your own.

Community
  • 1
  • 1
flob
  • 3,760
  • 2
  • 34
  • 57
  • thanks for your answer.i just study the http protocol,use socket can let me learn more. if the socket return 0,it mean i can close socket?and if use the "chunked",where i can see?or just do it myself? – cs x Jan 24 '15 at 11:06
  • If you read 0 from the socket/stream after a chunk while using chunked transfer encoding you could close the socket. If you meant the return value of the read call on the socket that returns 0 it does just mean that there is no data to read from the socket. It would return -1 if the connection got closed. – flob Jan 24 '15 at 15:38