如何获得仅包含某些参数的webrequest响应? [英] How can I get a webrequest response containing only some parameters?

查看:80
本文介绍了如何获得仅包含某些参数的webrequest响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!这可能是一个奇怪的问题,但是我从未真正使用过服务和端点,在这里我有一个很大的疑问.我们有一个应用程序,该应用程序从一些读者那里获取数据,并且必须使用与我们无关的另一个应用程序(iVadday)对其进行验证...因此,这些家伙要求我们在url中发送参数,例如"someurl.aspx?param1 =123¶ m2 = 3567564656 ...",他们将通过该网址"someurl.aspx?param3 =0¶m4= 54354"以相同的方式发送返回参数,所以我的问题是如何发送然后从该网址获取返回值? ??到目前为止,我尝试过使用发送如下参数的虚拟道具:

Hi! it might be a weird question but I never really worked with services and endpoints, and here I have a big doubt. We have an app that gets data from some readers and has to validate it with another app (iVadday) not related to us... so the guys requested us to send the parameters in the url like "someurl.aspx?param1=123¶m2=3567564656..." and they will send the return parameters the same way through that url "someurl.aspx?param3=0¶m4=54354" so my question is how to send and then retrieve the return values from that url??? so far, I tried with a dummy that sends parameters like this:

<code>
//I create he request and send the parameters read from the app
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:49198/Default.aspx?anden=" + anden + "&tag=" + tag + "&timeStamp=" + timeStamp);

request.Method = "POST";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

//I can get the stream as a string later
//How can I then get the parameters as they return?</code>



对此的响应是,如果我是对的,则整个流都包含带有html页面的标签,但是如果我想使用查询字符串来检索返回值怎么办?还是在这里不可能?我对这个要求和vadday感到很困惑.
我尝试使用我编写的名为Default的页面虚拟设备,该虚拟设备从Webrequest获取值.创建然后重定向到同一页面,但使用的是我将检索的新参数,现在对其进行了模拟.我想知道他们是否会使用params进行response.write,然后我必须解析流,或者他们将如何使用新的params调用页面,以便我可以查询字符串???如果有人可以分享一些光,我将深表感激!非常感谢你们很棒.



The response to this is the whole stream containing the tags with the html page if I''m correct but what if I want to use the query string to retrieve the return values? or is it not possible here? I''m quite confused with this requirement and with vadday as well.
I''ve tried with my page dummy named Default which I wrote, that gets the values from the Webrequest.Create and then redirects to the same page but with the new params that I''ll retrieve and are right now simulated. I''m wondering if they''ll do a response.write with the params and then I''ll have to parse the stream or how will they call the page with the new params so I can query the strings??? If anyone can share some light I''ll deeply appreciate it! thanks a lot guys you''re great

推荐答案

您将请求发送到其他应用程序的方法是正确的...
我了解的是您也想在相同的URL上读取响应(假设他们将在相同的URL查询字符串中发送响应).如果是这种情况,请确保在此页面上逐步进行操作.
1.
A.冻结"-param1,param2"之类的查询字符串参数名称,以将信息从您的应用程序发送到其他应用程序.然后
B.冻结要从其他应用程序在同一URL上接收到的查询字符串参数(其他应用程序要在同一URL上发送的数据)
2.假设在某些事件(例如按钮单击)上调用了上述用于发送请求的代码.
3.要读取响应,您需要在某些情况下在someurl.aspx
的同一页上的页面加载"中编写代码 在编写代码以读取查询字符串数据时,检查url中是否存在该参数(步骤1.B中的冻结参数)..u会很容易地从网络上获取如何检查url中参数的代码.这将确保您的网页仅当使用某些预定义参数点击页面时,加载代码才会执行​​.

我将尝试在一些示例代码中对此进行解释.

考虑u固定发送的参数名称是Param1和Param2.
因此,您的请求发送将类似于"someurl.aspx?param1 = 123& param2 = 356756465"
并且u固定了u将从响应中获取的参数为Param3和Param4

因此我们的页面加载代码如下所示:

Page_load()
{
if(!ispostback)
{
if(querystring contains("Param3 and Param4")
{
编写您的参数读取代码
}
}
}
注意:以上仅是示例.这不是正确的语法.您需要以正确的方式编写它.

我希望这能满足您的要求.
your approach to send the request to other application is correct...
what i understand is u want to read the response too on same URL (Assuming They will send the response in same URL query string). If this is the case then make sure u go step by step on this page.
1.
A.Freeze the Query-string parameter name Like "param1,param2" for sending information from ur app to other. and then
B. Freeze Query-string parameter that u want to received on same url from ur other application ( the data that other application going to send on same url )
2. it is assume that the above code for sending request is called on some event say Button click.
3. For reading the response u need to write the code on "page load" on same page in ur case on someurl.aspx
while writing the code to read the query-string data check whether that parameter ( freezed parameter in step 1.B is exist in the url..u will easily get the code on net how to check paramet in url. that will ensure ur page load code will excute only when the page is hit with some predefined parameter.

i will try to explain it in some sample code.

Consider u fixed the parameter name to send are Param1 and Param2.
So ur request sending will be like "someurl.aspx?param1=123&param2=356756465"
and u fixed the parameter that u will get from response as Param3 and Param4

so ur page load code will look like

Page_load()
{
if(!ispostback)
{
if(querystring contain("Param3 and Param4")
{
write ur parameter reading code
}
}
}
Note : Above is just example. it is not the proper syntax. u need to write it the correct way.

I hope this will full fill you requirement.


这篇关于如何获得仅包含某些参数的webrequest响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆