你好我试着用电子邮件信息发送PUT请求到指定的URL但是我得到一个错误:
"success":false,"error":"The request you sent is either invalid or too big."
我已经看过很多教程,但不能让它们中的任何一个工作。这是我一直在尝试的代码:
<?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);
任何帮助表示赞赏!
答案 0 :(得分:1)
它不是PHP,但它是解决方案之一:
curl -X PUT http://www.trikoder.hr/api/v1/RequestJobApplication/ -d email=bla@smth.com
祝你在求职面试中好运......
答案 1 :(得分:1)
它只是python中的几行,我已经检查过并且有效:)
我da majstore sretno na razgovoru:)
import requests
r = requests.put("http://www.trikoder.hr/api/v1/RequestJobApplication/", "email=spada4ever@hotmail.com")
print r.json()
答案 2 :(得分:0)
可能需要尝试以下代码。它会显示一些响应而不是错误。 你需要将post字段设置为true,并且还要为post字段自动生成查询字符串。 要么检查你的网址。 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);
我已经尝试并输出卷曲信息,确定需要检查你的结束和 输出是: -
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 )
关于put put请求如下: - Send PUT request with PHP cURL
答案 3 :(得分:0)
您必须在执行PUT
时定义内容的长度,否则它将无效。例如:
$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)),