简体   繁体   English

.NET 3.5CF WebRequest到Slim Framework

[英].NET 3.5CF WebRequest to Slim Framework

I'm writing a mobile application in .NET 3.5 Compact Framework and am trying to make a GET request to a PHP Slim Framework page. 我正在.NET 3.5 Compact Framework中编写移动应用程序,并且正在尝试向PHP Slim Framework页面发出GET请求。 If I try to access the page from a web browser on the local machine it works, but if I try to access it from the mobile device C# application or the mobile device's web browser I get a HTTP 404. I made a standard PHP page to display the current time and that works on all three of the above, so isolating the problem specifically to Slim pages. 如果我尝试从本地计算机上的Web浏览器访问该页面,它可以工作,但如果我尝试从移动设备C#应用程序移动设备的Web浏览器访问它,我会得到一个HTTP 404.我制作了一个标准的PHP页面显示当前时间并适用于上述所有三个,因此将问题专门隔离到Slim页面。 I also took a look at the access.log in xampp which looks like this: 我还看了一下xampp中的access.log,它看起来像这样:

[20/Mar/2013:17:07:38 +0000] "GET /SlimTest/ HTTP/1.1" 200 21 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"
[20/Mar/2013:17:09:37 +0000] "GET http://10.0.2.15/SlimTest/ HTTP/1.1" 404 523 "-" "-"

The first is from the local machine and the second is from the handheld device and, as you can see, the first request is completed successfully and the latter has a 404 returned to it. 第一个来自本地机器,第二个来自手持设备,如您所见,第一个请求成功完成,后者返回404。

The Slim PHP code looks like this: Slim PHP代码如下所示:

$app->get('/', function () {
    echo "This is the get route";    
});

And the C# looks like this: 而C#看起来像这样:

string webResponse = "";
try
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.0.2.15/SlimTest/");
    WebResponse response = request.GetResponse();
    using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
    {
        webResponse = streamReader.ReadToEnd();
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

It is important to note that I am not a web developer so I do apologise if it is something glaringly obvious. 重要的是要注意我不是一个Web开发人员,所以如果它显而易见,我会道歉。

Speed is also of the essence with this project so even if someone could suggest an alternative RESTful PHP framework which has proven to be useful to them, then I'd very much appreciate it. 速度也是这个项目的关键所在,所以即使有人可以建议一个已被证明对他们有用的替代RESTful PHP框架,那么我非常感谢它。

Finally, just for a quick insight, this project will have a web based application and a handheld mobile application that will communicate with a web service. 最后,为了快速了解,该项目将具有基于Web的应用程序和将与Web服务通信的手持移动应用程序。 I'm trying to get the web service written in PHP using slim so that it can be hosted on a Linux box to cut costs. 我正在尝试使用slim编写用PHP编写的Web服务,以便它可以托管在Linux机器上以降低成本。 Again, if anyone has any suggestions/alternatives then I'd be equally as grateful. 再说一次,如果有人有任何建议/替代方案,那么我同样会感激不尽。

Thanks 谢谢

  • Are you running your mobile app directly from Visual Studio or from the mobile device ? 您是直接从Visual Studio还是从移动设备运行移动应用程序?
  • Are you sure that your mobile device can access the right network (10.0.2.x) ? 您确定您的移动设备可以访问正确的网络(10.0.2.x)吗?
  • Don't worry about Slim, it fits perfectly your needs 不要担心Slim,它完全符合您的需求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM