首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >炮口6柱法不起作用

炮口6柱法不起作用
EN

Stack Overflow用户
提问于 2015-06-26 09:11:05
回答 1查看 900关注 0票数 1

我使用的是yii2和4,当我使用1.5时,我试图用postman发布数据,但是当我尝试使用php时,我说的是糟糕的请求404。

代码语言:javascript
运行
复制
error is GuzzleHttp\Exception\ClientException
v1/jobs/ [status code] 400 [reason phrase] BAD REQUEST

邮递员格式数据工作数据格式

代码语言:javascript
运行
复制
url -vm.xxx.com/v1/jobs/
 {
      "job_position":"Test Postion",
      "eligibility_course_id":["1","2","3","4"],
      "eligibiltiy_course_ids":["1","2","3","4"],
      "eligibility_branch_id":["5","6","7","8"],
      "eligibiltiy_skill_ids":["10","23","24"],
      "eligibiltiy_sublocation_ids":["10","23","24"],
      "location":["26","30","2","3"],
      "job_category":["1","4","7"],
      "sms_category":"1",
      "posting_date":"31\/07\/2014",
      "expiry_date":"31\/08\/2014",
      "job_type_id":"1",
      "job_type_other":"",
      "hiring_process":["1"],
      "job_description":"Test Description<\/p>",
      "company_name":"Test Company name",
      "company_profile":"Test company profile<\/p>",
      "company_url":"",
      "seo_title":"Test Seo Title",
      "seo_description":"Test Seo Description",
      "seo_keyword":"Test seo Keyward",
      "response":"1","how_to_apply":"",
      "terms_agreement":"1",
      "specify_terms_agreement":"",
      "employer_id":"1008369",
      "button_submitForm":"Post Job",
      "posted_by_id":"114",
      "template_name":"job_description"
    }

使用php代码方法-1

代码语言:javascript
运行
复制
$arr=[
"job_position" => "Test Postion",
"eligibility_course_id" => ["1","2","3","4"],
"eligibiltiy_course_ids" => ["1","2","3","4"],
"eligibility_branch_id" => ["5","6","7","8"],
"eligibiltiy_skill_ids" => ["10","23","24"],
"eligibiltiy_sublocation_ids" => ["10","23","24"],
"location" => ["26","30","2","3"],
"job_category" => ["1","4","7"],
"sms_category" => "1",
"posting_date" => "31\/07\/2014",
"expiry_date" => "31\/08\/2014",
"job_type_id" => "1",
"job_type_other" => "",
"hiring_process" => ["1"],
"job_description" => "Test Description<\/p>",
"company_name" => "Test Company name",
"company_profile" => "Test company profile<\/p>",
"company_url" => "",
"seo_title" => "Test Seo Title",
"seo_description" => "Test Seo Description",
"seo_keyword" => "Test seo Keyward",
"response" => "1","how_to_apply" => "",
"terms_agreement" => "1",
"specify_terms_agreement" => "",
"employer_id" => "1008369",
"button_submitForm" => "Post Job",
"posted_by_id" => "114",
"template_name" => "job_description"
];
$client = new Client();
$apiurl=Yii::$app->params['apiurl'];
$url=$apiurl.'/v1/jobs/';
try {

       $response = $client->post($url, ['json' => $arr]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e) {

    $req = $e->getRequest();
    $resp =$e->getResponse();
    echo "<pre>";
    var_dump($req);
    var_dump($resp);
    die('ss');
}

尝试方法-2

代码语言:javascript
运行
复制
 $arr=json_encode($arr);
$request = $client->post($url,array(
    'content-type' => 'application/json'
),array());
$request->setBody($arr); #set body!
$response = $request->send();

那我就得到

代码语言:javascript
运行
复制
InvalidArgumentException
No method is configured to handle the content-type config key
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-02 02:51:55

这是我的错误,我把错误的日期传给了朋友。

代码语言:javascript
运行
复制
"posting_date" => "31\/07\/2014",
"expiry_date" => "31\/08\/2014",

而不是这个,我有通行证

代码语言:javascript
运行
复制
"posting_date" => "31/07/2014",
"expiry_date" => "31/08/2014",

那就起作用了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31069234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档