hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Crawford <samcrawf...@gmail.com>
Subject Re: org.apache.http.ProtocolException: Invalid header: HTTP/1.1 200 OK
Date Tue, 29 May 2012 15:55:40 GMT
As an example, take a look at the bottom of
http://code.google.com/p/npr-android-app/source/browse/Npr/src/org/npr/android/news/StreamProxy.java
(specifically IcyLineParser and MyClientConnection).
MyClientConnection shows you how to override createResponseParser.

The unknown part for me is whether or not you can extend
BasicLineParser (like the author did for IcyLineParser) and get away
with just overriding parseHeader. This would require handling the
special case of the duplicate status line by returning null or a dummy
Header value in its place. Both are ugly, but then you're already
dealing with a broken web server, so I suspect such concerns are long
since gone!

I'm not able to test it myself right now, but hopefully the above will
provide you the necessary guidance to give it a try yourself. In the
meantime someone else may have a better suggestion than me.

Thanks,

Sam


On 29 May 2012 14:34, rpinto <santospinto.rafael@gmail.com> wrote:
>
> Hi Sam, thank you very much for your quick response.
>
> Is there any example/tutorial for how should hi implement
> createResponseParser?
>
> Thanks in advance,
>
> Best regards,
> RPinto
>
> Sam Crawford wrote:
>>
>> The issue will be caused by the web server replying with two "HTTP/1.1
>> 200 OK" headers. The web server you're connecting to is faulty.
>>
>> As a workaround, I would suggest subclassing
>> DefaultHttpClientConnection and overriding createResponseParser. See
>> here for more details:
>> http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/impl/AbstractHttpClientConnection.html#createResponseParser(org.apache.http.io.SessionInputBuffer,
>> org.apache.http.HttpResponseFactory,
>> org.apache.http.params.HttpParams)
>>
>> Hope this helps,
>>
>> Sam
>>
>>
>>
>> On 29 May 2012 14:10, rpinto <santospinto.rafael@gmail.com> wrote:
>>>
>>> Hi there,
>>>
>>> I'm using httpclient (4.1 and also 4.2) and it throws ProtocolException:
>>> Invalid header: HTTP/1.1 200 OK, and does not allow me to access de
>>> webcontent.
>>>
>>> Here is the stacktrace :
>>>
>>> Caused by: org.apache.http.ProtocolException: Invalid header: HTTP/1.1
>>> 200
>>> OK
>>>        at
>>> org.apache.http.impl.io.AbstractMessageParser.parseHeaders(AbstractMessageParser.java:226)
>>>        at
>>> org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
>>>        at
>>> org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
>>>        at
>>> org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
>>>        at
>>> org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
>>>        at
>>> org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
>>>        at
>>> org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
>>>        at
>>> org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:713)
>>>        at
>>> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:518)
>>>        at
>>> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
>>>
>>>
>>> And here are the Headers from the GET request:
>>>
>>> HTTP/1.1 200 OK
>>> Date: Fri, 09 Jan 1970 00:12:58 GMT
>>> Server: Boa/0.94.14rc18-ipcam
>>> Accept-Ranges: bytes
>>> Connection: close
>>> HTTP/1.1 200 OK
>>> Content-Type: multipart/x-mixed-replace;boundary=IPCAMJPG
>>>
>>> The problem must be Bold line because it does not respect HTTP/1.1.
>>>
>>> Is there any workaround or any fix?
>>>
>>> Thanks in advance,
>>>
>>> Best regards,
>>> Rafael Pinto
>>> --
>>> View this message in context:
>>> http://old.nabble.com/org.apache.http.ProtocolException%3A-Invalid-header%3A-HTTP-1.1-200-OK-tp33924984p33924984.html
>>> Sent from the HttpClient-User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
>>
> --
> View this message in context: http://old.nabble.com/org.apache.http.ProtocolException%3A-Invalid-header%3A-HTTP-1.1-200-OK-tp33924984p33925126.html
> Sent from the HttpClient-User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message