2

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!

kero
  • 10,647
  • 5
  • 41
  • 51
user2740217
  • 155
  • 1
  • 1
  • 8

4 Answers4

1

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...

Yax
  • 11
  • 2
1

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()
T0plomj3r
  • 685
  • 1
  • 9
  • 23
0

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

Community
  • 1
  • 1
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
  • still nothing :/, and my bad in CURLOPT_URL in the end is backslash so: http://www.trikoder.hr/api/v1/RequestJobApplication/ – user2740217 Mar 31 '14 at 13:15
  • whit this code i get: {"success":false,"error":"The request you sent is either invalid or too big. You ought to Google how to make a proper PUT request."} – user2740217 Mar 31 '14 at 13:22
  • but curl posting is ok you need to check what you send response on that url back – Rakesh Sharma Mar 31 '14 at 13:23
  • maybe i'm missing some key information, here is what task says to do: "send PUT request which contains email=your_email@xxx.com and get unique URL. API URL - http://www.trikoder.hr/api/v1/RequestJobApplication/ – user2740217 Mar 31 '14 at 13:30
  • now i get :{"success":false,"error":"Your request contains invalid data. Follow the instructions and send raw data."} – user2740217 Mar 31 '14 at 13:41
0

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)),
Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
  • still same error :/, {"success":false,"error":"Your request contains invalid data. Follow the instructions and send raw data."} – user2740217 Apr 01 '14 at 16:09