从 C# 为 Windows 7 Mobile 调用 php
我是 C#、php 和移动 win 7 上的整个编码的初学者。我的代码有问题,并且没有更多的论坛/网站可以搜索答案,所以我在这里发布查询。
我正在开发一个 Windows 7 移动项目,在我的代码中,我需要从 C# 调用 php 脚本,然后使用 php 返回的值。代码类似于:
string url = "../test.php";
req = (HttpWebRequest)WebRequest.Create(url);
IAsyncResult res = (IASync)req.BeginGetResponse(WebComplete, req);
private void Webcomplete(IAsyncResult a)
{
var req = (HttpWebRequest)a.AsyncState;
var res = req.EndGetResponse(a);
........
........
}
代码运行但没有任何反应。当我在 BeginGetResponse 处放置断点时,我发现它根本不调用 WebComplete。您知道为什么会发生这种情况以及解决方法是什么吗?另外,我如何将从 php 代码中获得的值分配给变量,以便我可以进一步操作数据。 注意:当我从浏览器测试时,url 返回正确的值。
感谢您的帮助 - 雷切尔
I have am a beginner in C#, php and the whole coding on mobile win 7. I have a problem with my code and there isnt any more forums/websites that i could search for the answer so i am posting the query here.
I am working on a windows 7 mobile project and in my code i need to call a php script from C# and later use the values that the php returns. The code is something like:
string url = "../test.php";
req = (HttpWebRequest)WebRequest.Create(url);
IAsyncResult res = (IASync)req.BeginGetResponse(WebComplete, req);
private void Webcomplete(IAsyncResult a)
{
var req = (HttpWebRequest)a.AsyncState;
var res = req.EndGetResponse(a);
........
........
}
The code runs but nothing happens. When i put a breakpoint at BeginGetResponse i find it does not call WebComplete at all. Would you know why this is happening and what is the workaround? Also how can i assign the value i get from the php code to a variable, so that i could further manipulate the data.
Note: The url returns the correct values when i tested it from the browser.
Thanks for the help - Racheal
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两件事要做。
首先,修复 php 文件的 url。正如 @ctacke 提到的,你指向本地设备...它不托管 php 文件,除非你发生了一些非常奇怪的事情。
第二个是可选的。不要执行异步请求,而是使其同步。例如:
至少,如果存在真正的问题,同步方法应该立即为您提供有关该问题的反馈。
Two things to do.
First, fix the url to the php file. As @ctacke mentioned the one you have points to the local device... which isn't hosting the php file unless you have some really weird stuff going on.
The second one is optional. Instead of doing an asynchronous request, make it synchronous. For example:
At the very least, if there is a real problem the synchronous method should give you immediate feedback on the issue.