Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
C# 使用PHP+;卷曲_C#_Php_Curl - Fatal编程技术网

C# 使用PHP+;卷曲

C# 使用PHP+;卷曲,c#,php,curl,C#,Php,Curl,我正在尝试使用PHP+cURL创建HTTP post请求,它与前面提到的文件“sendtoos.aspx.cs”的示例等效 我的PHP文件如下所示 <?php $uri = $_POST["uri"]; $title = $_POST["title"]; $subtitle = $_POST["subtitle"]; $file = 'file.txt'; //phpinfo(); $theData = '<?xml version="1.0" encodi

我正在尝试使用PHP+cURL创建HTTP post请求,它与前面提到的文件“sendtoos.aspx.cs”的示例等效

我的PHP文件如下所示

<?php 

$uri      = $_POST["uri"];
$title    = $_POST["title"]; 
$subtitle = $_POST["subtitle"];


$file = 'file.txt';
//phpinfo();
$theData = '<?xml version="1.0" encoding="utf-8"?>\\r';
$theData .= "<wp:Notification xmlns:wp=\"WPNotification\">";
$theData .=  "<wp:Toast>";
$theData .=  "<wp:Text1>" .$title;
$theData .=  "</wp:Text1>";
$theData .=  "<wp:Text2>" .$subtitle;
$theData .=  "</wp:Text2>";
$theData .= "<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>";
$theData .= "</wp:Toast>";
$theData .= "</wp:Notification>";   

$header_array = array('X-WindowsPhone-Target' => 'toast','X-NotificationClass' => '2','Content-type:' => 'text/xml','Content-length:' => strlen($theData));
$ch = curl_init();

curl_setopt($ch, CURLOPT_HTTPHEADER,$header_array);
curl_setopt($ch, CURLOPT_URL,$uri);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$theData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//print_r($ch);
$server_output = curl_exec ($ch);
//echo $server_outout;
//curl_close ($ch);

if (curl_errno($ch)) 
{ 
        print "Error: " . curl_error($ch); 
}
else 
{ 
 // Show me the result 
    print $server_output; 
    curl_close($ch); 
} 
//file_put_contents($file, $theData);
'toast'、'X-NotificationClass'=>'2'、'Content-type:'=>text/xml'、'Content-length:'=>strlen($theData));
$ch=curl_init();
curl_setopt($ch,CURLOPT_HTTPHEADER,$header_数组);
curl_setopt($ch,CURLOPT_URL,$uri);
curl_setopt($ch,CURLOPT_超时,60);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$theData);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//印刷费($ch);
$server\u output=curl\u exec($ch);
//echo$server\u out;
//卷曲关闭($ch);
if(旋度误差($ch))
{ 
打印“错误:”.curl\u错误($ch);
}
其他的
{ 
//给我看看结果
打印$server\u输出;
卷曲关闭($ch);
} 
//文件内容($file,$theData);
?>


有人能告诉我我做错了什么吗?我也尝试使用HTTPRequest类来创建这个示例,但我在配置php_http.dll扩展名时遇到了困难,似乎该文件有依赖项或已损坏。尽管如此,这方面的帮助还是很好的。

尝试使用
urlencode
并首先为POST准备变量

$postedfield="MYPOST=".urlencode($theData);
然后使用这个变量

curl_setopt($ch, CURLOPT_POSTFIELDS,$postedfield);

并解码发布的值

您以错误的方式设置http头(
$header\u array
)。用这个

$header_array = array(
  'X-WindowsPhone-Target: toast',
  'X-NotificationClass: 2',
  'Content-type: text/xml'
);

如果这不起作用,请从上面将
text/xml
更改为
application/xml

请告诉我们您遇到的错误或不正确的行为。对不起,伙计,我对php输出函数不太熟悉,我能告诉你的是,如果一切正常,它将向我的手机应用程序发送通知(ASP示例工作正常,它发送通知,意味着phoneapp可以接收),server_输出变量不返回任何内容,它为空,或者可能是我不知道如何准确打印它,您能提示我如何打印错误代码或响应数据吗?如果您忘记了对帖子数据进行url编码,那将非常有帮助:curl_setopt($ch,CURLOPT_POSTFIELDS,urlencode($theData));谢谢,让我试试。尝试过url编码,但没有改变:-(把你的问题分成几部分。首先尝试不使用任何标题,并尝试以文本形式输出变量。如果正在输出变量,则可能需要使用有效的xml格式,以便让C#从我学到的各种示例中了解需求。无论如何,感谢你的回复。