Question

hello im trying send PUT request with email information to specified url but im getting an error:

"success":false,"error":"The request you sent is either invalid or too big."

I've seen many tutorials but cant make any of them work. This is code i've been trying:

<?php 
$handle = curl_init();

curl_setopt_array(
    $handle,
    array(
        CURLOPT_URL => "http://www.trikoder.hr/api/v1/RequestJobApplication/",
        CURLOPT_POSTFIELDS => "?email=xxx@gmail.com",
        CURLOPT_RETURNTRANSFER => true
    )
);

$response = curl_exec($handle);
curl_close($handle);
echo '<pre>';
print_r($response);

any help is appreciated!

Was it helpful?

Solution

It's just few lines in python, I've checked and it works :)

I da majstore sretno na razgovoru :)

 import requests

    r = requests.put("http://www.trikoder.hr/api/v1/RequestJobApplication/", "email=spada4ever@hotmail.com")
    print r.json()

OTHER TIPS

It's not in PHP but it's one of the solutions:

curl -X PUT http://www.trikoder.hr/api/v1/RequestJobApplication/ -d email=bla@smth.com

Good luck with job interview...

may be you need to try below code. it will showing some response not an error. you need to set post fields to true and also curl auto make query string for post fields. either check your url . http://www.trikoder.hr/api/v1/RequestJobApplication/

$handle = curl_init();

curl_setopt_array(
    $handle,
    array(
        CURLOPT_URL => "http://www.trikoder.hr/api/v1/RequestJobApplication/",
         CURLOPT_POST=> 1,
        CURLOPT_POSTFIELDS => "email=xxx@gmail.com",
        CURLOPT_RETURNTRANSFER => true
    )
);

$response = curl_exec($handle);
$output = curl_getinfo($handle);
print_r($output);
curl_close($handle);
echo '<pre>';
print_r($response);

i have tried and output of curl info is ok need to check your end and output is:-

Array ( [url] => http://www.trikoder.hr/api/v1/RequestJobApplication/ [content_type] => application/json; charset=utf-8 [http_code] => 200 [header_size] => 341 [request_size] => 172 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.904 [namelookup_time] => 0 [connect_time] => 0.421 [pretransfer_time] => 0.421 [size_upload] => 19 [size_download] => 132 [speed_download] => 146 [speed_upload] => 21 [download_content_length] => 132 [upload_content_length] => -1 [starttransfer_time] => 0.904 [redirect_time] => 0 )

for about put request follow :- Send PUT request with PHP cURL

You must define the length of content when doing PUT otherwise it will not work. Example:

$fields = "email=xxx@gmail.com";

CURLOPT_URL => "http://www.trikoder.hr/api/v1/RequestJobApplication/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => $fields,
// this is must for PUT
CURLOPT_HTTPHEADER => array('Content-Length: ' . strlen($fields)),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top