Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用php发送头中带有参数的post请求_Javascript_Php_Api_Post - Fatal编程技术网

Javascript 如何使用php发送头中带有参数的post请求

Javascript 如何使用php发送头中带有参数的post请求,javascript,php,api,post,Javascript,Php,Api,Post,我正在尝试使用我的web应用发送短信。我发现API可以帮助我做到这一点,但它的文档很差 我需要的是使用PHP发送请求 最后,我使用JavaScript正确地发送了请求。现在我想用PHP做同样的事情 var Username="abcdefg" var password="123456789" var language="1" var sender="mysenderid" var Mobile= mobile var message= "Dear name would you please gi

我正在尝试使用我的web应用发送短信。我发现API可以帮助我做到这一点,但它的文档很差

我需要的是使用PHP发送请求

最后,我使用JavaScript正确地发送了请求。现在我想用PHP做同样的事情

var Username="abcdefg"
var password="123456789"
var language="1"
var sender="mysenderid"
var Mobile= mobile
var message= "Dear name would you please give us your feedback about your last order click here "

$.post(`https://smsmisr.com/api/webapi/?Username=${Username}&password=${password}&language=${language}&sender=${sender}&Mobile=${Mobile}&message=${message}`, function (data){
    console.log(data);
});

在php中,您可以按如下方式执行:

<?php

$request = new HttpRequest();
$request->setUrl('YOUR_END_POINT e.g. https://www.google.ca');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
    'cache-control' => 'no-cache',
    'Content-Type' => 'application/json; charset=utf-8',
    'PARAM1' => '990d16da-31d9-4961-a340-e21caf0a13d7',
    'PARAM2' => 'no-cache',
    'app_version' => '0.0.0.1',
    'app_name' => 'YOUR_APP_NAME'

));

$request->setBody('{
     "ID" : "80E1CB93-52de-4cd1-abd9-5786e4e616c8",
     "PHONE": "+14574544460",
     "SIN": "027899876557",
     "Auth" : "A",
     "other": "othervalue"
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'