mardi 21 avril 2015

Building HTTP POST request for registering printer with Google Cloud Print service

Vote count: 0

I am trying to register a printer by sending a HTTP POST request using the Google Cloud Print register API at:

http://ift.tt/1J7osHT

Here's my source code:

void IllustratePostWithData(const char* url, HttpTransport* transport){

    scoped_ptr<HttpRequest> request(transport->NewHttpRequest(HttpRequest::POST));
    request->AddHeader("X-CloudPrint-Proxy", "my proxy");
    request->set_content_type("multipart/form-data; boundary=-----------RubyMultipartPost");
    request->HttpHeader_CONTENT_LENGTH;
    request->set_url(url);
    util::Status status = request->Execute();
    if (!status.ok())
        cerr << status.error_message();

    HttpResponse *response = request->response();
    if (response->ok()) {
        cout << "Success" << endl;
    } else {
        cout << "Failed with status=" << response->status().error_message() << endl;
    }
    string body;
    util::Status stat = response->GetBodyString(&body);
    cout << "Received HTTP status code =" << response->http_code() << endl;
    if (stat.ok()) {
        cout << "HTTP body" << body << endl;
    }
}

int main() {
    char* Cloud_print_url = "http://ift.tt/1JqX44f";
    scoped_ptr<HttpTransport> transport;

    HttpTransportFactory* factory = new CurlHttpTransportFactory();
    HttpTransport* globalTransport = factory->New();

    IllustratePostWithData(Cloud_print_url, globalTransport);
    return 0;
}

I get the following response:

Success
Received HTTP status code =200
HTTP body{
 "success": false,
 "message": "Proxy ID is required.",
 "request": {
  "time": "0",
  "params": {
  }
 },
 "errorCode": 115
}

Going through the API, I could not find a function to set proxy. Am I missing out on something in the HTTP POST request?

Thanks

asked 2 mins ago



Building HTTP POST request for registering printer with Google Cloud Print service

Aucun commentaire:

Enregistrer un commentaire