Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse error - unexpected end of input #558

Closed
alienzj opened this issue Apr 18, 2017 · 4 comments
Closed

parse error - unexpected end of input #558

alienzj opened this issue Apr 18, 2017 · 4 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@alienzj
Copy link

alienzj commented Apr 18, 2017

#include <cpprest/http_client.h>
#include <nlohmann/json.hpp>
#include <iostream>
int main() {
	 web::uri_builder builder("http://xkcd.com/614/info.0.json");   // first builder
     // web::uri_builder builder("http://i.jandan.net/?oxwlxojflwblxbsapi=jandan.get_duan_comments?page=25");   // second builder
        web::http::client::http_client client(builder.to_uri());
        nlohmann::json json = nlohmann::json::parse(client.request(web::http::methods::GET)
                              .get().extract_string().get());
        std::cout << json << std::endl;
}

Second builder can run.
But when run first builder, i will get:
terminate called after throwing an instance of 'std::invalid_argument'
what(): parse error - unexpected end of input
[1] 2056 abort (core dumped) ./bin/xkcd_bot

Please help me! Thanks very much!

@nlohmann
Copy link
Owner

nlohmann commented Apr 19, 2017

Can you make sure that the HTTP client is following redirections? I get the following output with httpie;

$ http http://xkcd.com/614/info.0.json
HTTP/1.1 301 Moved Permanently
Accept-Ranges: bytes
Connection: close
Content-Length: 0
Date: Wed, 19 Apr 2017 17:02:46 GMT
Location: https://xkcd.com/614/info.0.json
Retry-After: 0
Server: Varnish
Via: 1.1 varnish
X-Cache: HIT
X-Cache-Hits: 0
X-Served-By: cache-fra1228-FRA
X-Timer: S1492621366.171241,VS0,VE0

As you can see, the content-length is 0 bytes, so the error message "unexpected end of input" would make sense ;-)

The redirect URL (https://xkcd.com/614/info.0.json) as well as the second URL return proper JSON with a 200 status code.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Apr 19, 2017
@alienzj
Copy link
Author

alienzj commented Apr 20, 2017

OK, I know, thank you very much!

@nlohmann
Copy link
Owner

Was that the issue?

@alienzj
Copy link
Author

alienzj commented Apr 20, 2017

Nothing~

@alienzj alienzj closed this as completed Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants