2012-07-20 76 views
0

我现在习惯了Visual Basic,并试图建立一个应用程序,我们的操作员可以将快速搜索提交给我们的系统之一。 - 我环顾四周,这和我无法找到很多信息Visual Basic 2010 Html表格

下面是对我们所希望的简要概述,以达到某种方式

1. VB 2010 App (2 x Text Boxes + Button) 
2. PHP Script (If query = bob & jones <<= 
3. Curl PHP Request to another PHP Form 
4. Returns to Original PHP Script <<= 
5. Somehow returns information back to .net application that is waiting 

我是一个PHP程序员,而不是一个.NET开发人员主要是让卷曲和PHP脚本大多完成它只是在.NET编码

让我们开始我们用下面的代码:

Dim webStream As Stream 

    Dim webResponse = "" 

    Dim req As HttpWebRequest 

    Dim res As HttpWebResponse 

    ' API Address '' 

    req = WebRequest.Create("xxxxxxxxx") 



    req.Method = "GET" ' Method of sending HTTP Request(GET/POST) 

    res = req.GetResponse() ' Send Request 



    webStream = res.GetResponseStream() ' Get Response 

    Dim webStreamReader As New StreamReader(webStream) 

    ' READ Response in one Variable 

    While webStreamReader.Peek >= 0 

     webResponse = webStreamReader.ReadToEnd() 

    End While 
    MsgBox(webResponse) 

这是WO因为它以信息箱的形式将信息带回给我们,虽然我们希望它能填充几个文本框(不知道这是否可能)(012甚至不知道这是否可能)

但是主要问题是它检索网站的源代码,而不仅仅是信息在网站上的文字侧

感谢

+0

webResponse中的数据格式是什么,你如何描述它? – 2012-07-20 18:38:14

+0

嗨在web响应标记格式只是HTML网站的完整标记​​标记很多 - 代码是我们发现在互联网上的一块,只是为了让球滚动,所以我不太确定它可以改变多远 – 2012-07-20 18:42:37

+0

看看这个[SO qiestion/answer](http://stackoverflow.com/questions/516811/how-do-you-parse-an-html-in-vb-net)他们是推荐Html Agility Pack来解析Html – 2012-07-20 19:09:09

回答

0

你似乎有这部分的方式已经完成。你有标记,只是深入研究。

这是上面编写代码的另一种方法。

Dim MyURL as string = "xxxxxxx" 
Dim MyRequest As WebRequest = WebRequest.create(MyURL) 
MyRequest.Headers.Add("myCustom","true") 'PHP Web Server @ xxxxxxx will see this as $_SERVER['http_myCustom'] - true 
MyRequest.ContentType = "text/html" 
MyRequest.Method = "GET" 

Dim MyResponse As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) 

If MyResponse.StatusCode = HttpStatusCode.OK Then 
    Dim SR As New StreamReader(MyRequest.GetResponseStream()) 
    MyRequest.Close() 
    Dim webResponse As String = SR.ReadToEnd() 
    SR.Close() 

    'At this point, the source of the page is in webResponse 

Else 
    MyRequest.Close() 
    'Error in connection to remote/host server 
End If 

我添加页眉请求表明,你可以简单地检查这个头的存在,和/或引荐,在外部网站以处理该网站不同的反应..这是,如果您不想在webRequest中解析整个源代码,则应该考虑不从外部网站发送整个文档。

对于,我假设你只是想获得由外部服务器解析为text/html的搜索结果。