donmqryh49993 2019-04-04 20:26
浏览 246

获取post发送参数但不返回curl数据

The question is some what related to this one, but I can't get my answer there.

Lead Submitting function:

export async function submitLeads(fdata) {
  let url = baseUrl+"/submit";
  let headers = new Headers();
  headers.append("Content-Type", "multipart/form-data")
  const response = await fetch(url, {
     method: "POST",
     body: fdata,
     header: headers
  });
if (response.ok) {
     return response.json()
}  else {
     console.log("There seems to be some error in fetching data" + response.statusText);
  }
}

PHP Lead submitting function:

public function processLeads(Request $request)
{
    $a_formSubmit = $request->request->all();
    $response = json_decode($this->curlPost(LEAD_END_POINT, $a_formSubmit), true);
    //echo json_encode($a_formSubmit);//still fine I am getting my input
    //exit;
    if ($isValidResult = isset($response['status']) && $response['status'] == 101) {
        //echo json_encode($response);//Here no I am getting a empty $response['data']; why??
        //exit;
        $this->setSubmittedSchools($session, $response['data']);
        LeadResponseLogger::logLeadResponse($a_formSubmit, $response['data']);
        echo json_encode($response['data']);
    }
}

Curl Post function:

let formData = this.leadSubmitFields(this.state, this.props.appState);
submitLeads(formData).then((lead) => {
    console.log(lead);
});
  • I am creating and appending data through formData() object. I send them to a api call function(submitLeads).
  • It reaches the given PHP (Action in drupal module)function and in turn the php function calls another one which is a curl call.
  • the curl function (curlPost) should return the data, it is returning empty value, but returns correct value in postman.
  • I am not sure whether I have to change my request "content-type" or something else in .htaccess file of drupal.
  • I did this in my local, so I already set Access Control Allow Origin "*" on .htaccess.
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100