使用变量作为URL字符串中的参数时使用WebRequest.Create(URL)时出现问题 [英] Issue when using WebRequest.Create(URL) when using variables as parameters in the URL string
问题描述
当我创建WEB API请求时,当我使用变量而不是URL中的参数的精确值时,为什么有人会帮助我,为什么我得到一个空的响应? ?
Can anybody help me please why do I get an empty response when I use variables instead of exact values for parameters in URL when I create the WEB API request?
我有这个:
WebRequest request = WebRequest.Create(
" http:// path / controller / action?id =" + id.ToString()+"& accountNo =" + accountNo + QUOT;&安培;散列= QUOT; +散列);    哪个
给我回复为空字符串。
WebRequest request = WebRequest.Create(
"http://path/controller/action?id="+id.ToString()+"&accountNo="+accountNo+"&hash="+hash); which
gives me response as empty string.
                                                                       
                                                         如果我使用:
If I use:
WebRequest request = WebRequest.Create(" http:// path / controller / action?id = 2& accountNo = 98989898&散列= 65bbfbacba7435aed714ea3a4e9fc97ec92509b2c97d5");
WebRequest request = WebRequest.Create("http://path/controller/action?id=2&accountNo=98989898&hash=65bbfbacba7435aed714ea3a4e9fc97ec92509b2c97d5");
我得到的答案是正确的。
I get the response which is correct.
谢谢!
推荐答案
您是否已经调查了这些字符串?例如:
string s1 = "http://path/controller/action?id=" + id +"&accountNo=" + accountNo + "&hash=" + hash;
string s2 = "http://path/controller/action?id=2&accountNo=98989898&hash=65bbfbacba7435aed714ea3a4e9fc97ec92509b2c97d5";
bool are_equal = s1 == s2;
如果 are_equal 为false,则可能是变量( id ,
accountNo , hash )不包含预期值。使用调试器继续研究。
If are_equal is false, then probably the variables (id, accountNo, hash) do not contain the expected values. Continue your research using the Debugger.
这篇关于使用变量作为URL字符串中的参数时使用WebRequest.Create(URL)时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!