cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: using libcurl for ipp

From: benoy m <benoy6751_at_gmail.com>
Date: Fri, 19 Sep 2008 16:55:27 -0500

On Fri, Sep 19, 2008 at 3:56 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Fri, 19 Sep 2008, benoy m wrote:
>
> So I have built the http request data for content type: application/ipp
>> and
>> store it as a byte array.
>> vector<unsigned char> postdata;
>>
>> Then I make the following calls:
>> curl_easy_setopt( handle, CURLOPT_POSTFIELDSIZE, postdata.size());
>> curl_easy_setopt( handle, CURLOPT_POSTFIELDS , &postdata);
>>
>
> CURLOPT_POSTFIELDS expects a plain C char *, so I hope your C++isms convert
> it to such a one.
>
> Then I create the response headers:
>>
>
> No, libcurl is a client it sends request headers.
>
> responseHeaders = curl_slist_append( responseHeaders ,
>> "Transfer-Encoding: chunked" ) ;
>>
>
> chunked encoding will be wrong and downright confusing, you already provide
> the expected size of the POST.
>
> responseHeaders = curl_slist_append( responseHeaders , "Content-Type:
>> application/ipp" ) ;
>>
>> However, I kept getting "HTTP/1.1 400 Bad Request" from the print server.
>>
>
> And no hints at all from the server what the problem is?
>
> So I have read a little more and found that using CURLOPT_POSTFIELDS sets
>> Content-Type to application/x-www-form-urlencoded by default in the
>> header.
>>
>
> Yes, but your Content-Type: header replacement change that.
>
> So, since the Content-Type for ipp is, application/ipp, i did
>> curl_easy_setopt(handle, CURLOPT_POST, 0).
>>
>
> You still want it to be a POST. Or?
>
> And I would really recommend using CURLOPT_DEBUGFUNCTION (see the debug.c
> example) to get to see exactly what libcurl sends and receives.
>
> --
>
> / daniel.haxx.se

Sorry the repsonseHeaders should have been requestHeaders.
I didn't realize that Content-Type: application/ipp would override the
default Contetnt-Type.

Yes I do want it to be a post.

I did try the CURLOPT_DEBUGFUNCTION and this is what I get.

== Info: About to connect() to 10.169.106.119 port 631 (#0)
== Info: Trying 10.169.106.119... == Info: connected
== Info: Connected to 10.169.106.119 (10.169.106.119) port 631 (#0)
== Info: Server auth using Basic with user 'root'
=> Send header, zd bytes (0xzx)
zx: POST /printers/CUPSPRINTER HTTP/1.1
zx: Authorization: Basic cm9vdDpjZXJuZXI=
zx: Host: 10.169.106.119:631
zx: Accept: */*
zx: Content-Type: application/ipp
zx: Content-Length: 187
zx:
=> Send data, zd bytes (0xzx)
zx: ..2.C.2...2.1.0_....n\client...u4R..............Content-Length:
zx: 187....a4R......./2...2../2.ibute-fidelity2.".."5R....2../2.....
zx: ipp-attribute-fidelity.4:631....7R....2../2.....7R....2../2
<= Recv header, zd bytes (0xzx)
zx: HTTP/1.1 400 Bad Request
<= Recv header, zd bytes (0xzx)
zx: Date: Fri, 19 Sep 2008 21:48:12 GMT
<= Recv header, zd bytes (0xzx)
zx: Server: CUPS/1.1
<= Recv header, zd bytes (0xzx)
zx: Content-Language: en_US
<= Recv header, zd bytes (0xzx)
zx: Upgrade: TLS/1.0,HTTP/1.1
<= Recv header, zd bytes (0xzx)
zx: Connection: close
<= Recv header, zd bytes (0xzx)
zx: Content-Type: text/html
<= Recv header, zd bytes (0xzx)
zx: Content-Length: 156
<= Recv header, zd bytes (0xzx)
zx:
<= Recv data, zd bytes (0xzx)
zx: <HTML><HEAD><TITLE>400 Bad Request</TITLE></HEAD><BODY><H1>Bad R
zx: equest</H1>Your browser sent a request that this server could no
zx: t understand.</BODY></HTML>.

I assume that after the necessary changes have been made, all the curl
function calls are correct. So the reason I am getting this error might be
with the data being send :
    curl_easy_setopt( handle, CURLOPT_POSTFIELDS , &postdata)

is incorrect. Is there any way I can print out the raw data that is send? I
see that some of the data i have send can be seen, ex: "zx:
ipp-attribute-fidelity.4:"

Thanks,

benoy
Received on 2008-09-20