Home » U++ Library support » U++ MT-multithreading and servers » httprequest fails getting entire url content
httprequest fails getting entire url content [message #57711] |
Wed, 01 December 2021 14:57 |
aquilarubra
Messages: 24 Registered: December 2019
|
Promising Member |
|
|
Hi,
I am experiencing a strange behavior with HttpRequest. It has to get a json page through authorization. It works through a browser, but with HttpRequest it only gets an initial part, then truncates the output with "ERROR: Unexpected end of text."
Any idea what could go wrong?
From the inspector in Firefox I see that only one URL is called. So, no redirections, etc.
|
|
|
|
|
|
|
Re: httprequest fails getting entire url content [message #57820 is a reply to message #57721] |
Sun, 19 December 2021 15:06 |
|
mirek
Messages: 14162 Registered: November 2005
|
Ultimate Member |
|
|
aquilarubra wrote on Thu, 02 December 2021 09:58I got the xml not parsed with this, copied from Firefox' Inspector:
request.Accept("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8");
However, I think that HttpRequest must be reviewed.
Is it possible to have url that is causing this problem?
If not, have you checked with browser that the server is serving the complete content? (Probably yes, but it is always good to check).
Mirek
|
|
|
Re: httprequest fails getting entire url content [message #57821 is a reply to message #57720] |
Sun, 19 December 2021 15:10 |
|
mirek
Messages: 14162 Registered: November 2005
|
Ultimate Member |
|
|
aquilarubra wrote on Thu, 02 December 2021 09:37I'm trying to debug.
I see that the source is something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><result><metadata><count>1</count><limit>20</limit><offset>0</offset></metadata><smsList><sms>...
But I get this in HttpResponse:
{"metadata":{"count":1,"offset":0,"limit":20},"smsList":ERROR: Unexpected end of text.
So, the xml parser is engaged by HttpResponse. I see that the error "Unexpected end of text" is in uppsrc/ide/Designers/Xml.cpp, uppsrc/ide/Xml.cpp, and uppsrc/RichText/ParseQtf.cpp
I tried with request.ContentType("text/plain"), but it is still parsed. Is there any way to bypass that behavior?
Ah, this looks like server returns either JSON or XML, based on Accept, defaulting to JSON unless you specify you want XML.
I think .Accept("application/xml") should fix the problem (no need for the long text).
Alternatively, you can simply use JSON (but probably specify .Accept("application/json") just to be futureproof) and ParseJSON instead. JSON is better format anyway...
[Updated on: Sun, 19 December 2021 15:10] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Dec 14 14:26:56 CET 2024
Total time taken to generate the page: 0.03083 seconds
|