Quantcast
Channel: Questions in topic: "httpwebrequest"
Viewing all articles
Browse latest Browse all 190

get a mysterious problem,when i use HttpWebRequest in unity c# script.

$
0
0
in script,i use HttpWebRequest to get service from network.but it comes a mysterious problem. the source code: string url = "http://apis.baidu.com/apistore/vop/baiduvopjson"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); print(request.Address); request.Method = "get"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); StreamReader Reader = new StreamReader(s, Encoding.UTF8); string strValue = ""; strValue = Reader.ReadToEnd(); print (strValue); the result is like(i have copy the html to a html file): ![alt text][1] [1]: /storage/temp/69776-1.jpg but the mysterious problem comes.when i use this code in Visual studio c# project,here is the source code: string url = "http://apis.baidu.com/apistore/vop/baiduvopjson"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "get"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); StreamReader Reader = new StreamReader(s, Encoding.UTF8); string strValue = ""; strValue = Reader.ReadToEnd(); Console.WriteLine(strValue); the result which is true in fact is as follows: {"errNum":300202,"errMsg":"Missing apikey"} do some one know what mistake do i make in unity project? why can i get the ture httpweb response?

Viewing all articles
Browse latest Browse all 190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>