Skip to content

parse error - unexpected end of input #558

Closed

Description

@alienzj
#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!

Activity

  1. nlohmann commented on Apr 19, 2017

    @nlohmann
    Owner

    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.

  2. alienzj commented on Apr 20, 2017

    @alienzj
    Author

    OK, I know, thank you very much!

  3. nlohmann commented on Apr 20, 2017

    @nlohmann
    Owner

    Was that the issue?

  4. alienzj commented on Apr 20, 2017

    @alienzj
    Author

    Nothing~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions