简体   繁体   中英

Bad Request 400 Curl Problem

It seems like im getting a problem when Im trying to send a request to a server in php. The http api request is something like this:

https://www.quickbase.com/db/basddzvkb?act=API_DoQuery&ticket=6_bsdaaap8y_by5bx6_b_crji7wwewew3b9asd5zibmf8jh3bhsdsddvhruc9csquzdg9bzw4&apptoken=cgsb5xdwehusdaaagcjs222dz9&fmt=structured&query= {'22'.ct.'test'}

I have the following part of my code in php where I believe the error is occuring:

else
    {
        $ch = curl_init($input);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //curl_setopt($ch, CURLOPT_POST, true);
        $this->input = $input;

    }

    $r = curl_exec($ch);

    print_r(curl_getinfo($ch));


    if($return_xml) {
        $response = new SimpleXMLElement($r);
    }

This is what I get from the print_r(curl_getinfo($ch)) statement:

[content_type] => text/html [http_code] => 400 [header_size] => 129 [request_size] => 251 [filetime] => -1 [ssl_verify_result] => 20 [redirect_count] => 0 [total_time] => 0.281 [namelookup_time] => 0 [connect_time] => 0.063 [pretransfer_time] => 0.188 [size_upload] => 0 [size_download] => 20 [speed_download] => 71 [speed_upload] => 0 [download_content_length] => 20 [upload_content_length] => 0 [starttransfer_time] => 0.281 [redirect_time] => 0 [certinfo] => Array ( )

Also as you can see that I commented out the curlopt_post, its because it was causing problems when I was doing a different api request. Im not sure what the solution can be and I have been looking at this problem for awhile now hopefully someone can help me thanks :)

Datasage helped me come up with this answer, you basically have to add urlencode("{'22'.ct.'test'}"); to this part of the code and it will produce the correct output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM