0

I am trying to register a printer with the Google Cloud Print service using the register API at:

https://developers.google.com/cloud-print/docs/proxyinterfaces#register

I am trying to send a HTTP POST request using Google API Client Library for c++.

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->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 = "https://www.google.com/cloudprint/register";
    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

ap6491
  • 805
  • 1
  • 10
  • 26
  • What is `request->HttpHeader_CONTENT_LENGTH` supposed to do? – Alan Stokes Apr 21 '15 at 18:32
  • The documentation you linked to lists a large number of required parameters (including "proxy (required)"). You don't seem to be passing any of them. – Alan Stokes Apr 21 '15 at 18:34
  • @AlanStokes request->HttpHeader_CONTENT_LENGTH was not needed. I was trying to set a content length value for it so I removed it from the code for now. – ap6491 Apr 21 '15 at 18:38
  • @AlanStokes Regarding proxy, the Google API Client does not have functions to set proxy. That's exactly my question whether there is an alternative way to set proxy. Thanks. – ap6491 Apr 21 '15 at 18:40
  • 1
    So, I'm no web developer. But they asked for those parameters to be sent via a multipart POST. Have you tried sending those parameters via [multipart POST](http://stackoverflow.com/questions/913626/what-should-a-multipart-http-request-with-multiple-files-look-like)? – Yakk - Adam Nevraumont Apr 21 '15 at 20:28

0 Answers0