PHP post to WebAPI -
well, know headline simple, looking 3 days example on how make post
request webapi
.
currently using jquery
post
, need php script run , talk c# webapi
, , seems impossible find examples or explain on how that.
someone gave me code :
$response = file_get_contents('http://localhost:59040/api/email/sendemails'); $response = json_decode($response); echo ($response);
but 1 nothing - not error on how go more problem.
i simpley need php script make post
request webapi gets 1 param(string) , return ok answer or error,
after maalls answer post how send post request php?
the answer simple , code following :
$url = 'http://server.com/path'; $data = array('key1' => 'value1', 'key2' => 'value2'); // use key 'http' if send request https://... $options = array( 'http' => array( 'header' => "content-type: application/x-www-form-urlencoded\r\n", 'method' => 'post', 'content' => http_build_query($data), ), ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); var_dump($result);
thanks maalls , dbau answer :).
Comments
Post a Comment