【转】get a mysterious problem,when i use HttpWebRequest in unity c# script
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):
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?
个解答,截止elenzil · 05月10日 18:42
the problem is not your use of HTTPWebRequest, the problem is your use of the remote service. if you use command-line "curl" with the same URL, you get the same response:
curl http://apis.baidu.com/apistore/vop/baiduvopjson{"errNum":300202,"errMsg":"Missing apikey"}
or even just visit http://apis.baidu.com/apistore/vop/baiduvopjson in a browser - same response.
it seems like you should be providing an API key somehow. maybe as a form parameter, maybe as a URL parameter, header param, etc, etc. you should look up the docs for whatever service that is.
I have found the point of my problem....The string of request method should be uppercase....omg,the mono .net has such a slight difference with .net framework. Anyway,thanks for your reply.
【转】get a mysterious problem,when i use HttpWebRequest in unity c# script的更多相关文章
- python模块:logging
# Copyright 2001-2016 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and ...
- python中的logger模块
logger 提供了应用程序可以直接使用的接口handler将(logger创建的)日志记录发送到合适的目的输出filter提供了细度设备来决定输出哪条日志记录formatter决定日志记录的最终输出 ...
- python中的logger模块详细讲解
logger 提供了应用程序可以直接使用的接口handler将(logger创建的)日志记录发送到合适的目的输出filter提供了细度设备来决定输出哪条日志记录formatter决定日志记录的最终输出 ...
- threading.RLock()
# Copyright 2001-2017 by Vinay Sajip. All Rights Reserved.## Permission to use, copy, modify, and di ...
- A Study of WebRTC Security
转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...
- easily add files to META-INF in NetBeans
http://georgeinfo.blog.163.com/blog/static/16368334120101019104044650/ ————————————————————————————— ...
- 部署的docker image总是太大,怎么办?
sudo docker images REPOSITORY TAG IMAGE ID CREATED ...
- Unity 5 Game Optimization (Chris Dickinson 著)
1. Detecting Performance Issues 2. Scripting Strategies 3. The Benefits of Batching 4. Kickstart You ...
- Cross compiling coreutils and generate the manpages
When we cross compiling coreutils, there is an problem of generating man pages, because the source s ...
随机推荐
- loj 1154(最大流+枚举汇点)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26868 思路:拆点,容量为最多能跳的步数,然后设立一个超级源点,源 ...
- 小甲鱼PE详解之区块表(节表)和区块(节)(PE详解04)
到此为止,小甲鱼和大家已经学了许多关于 DOS header 和 PE header 的知识.接下来就该轮到SectionTable (区块表,也成节表).(视频教程:http://fishc.com ...
- Windows计数器做性能监控(window server 2008服务器)
使用Windows计数器 一.创建数据收集器集 二.创建数据收集器 三.使用数据收集器 1.修改数据收集器的属性 2.手动启用.手动停止数据收集器集 3.计划任务 4.在性能监视器中查看 一.性能监视 ...
- HashMap两种遍历数据的方式
HashMap的遍历有两种方式,一种是entrySet的方式,另外一种是keySet的方式. 第一种利用entrySet的方式: Map map = new HashMap(); Iterator i ...
- 简单几何(线段相交) POJ 2653 Pick-up sticks
题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /******************************************** ...
- SGU438 The Glorious Karlutka River =)(最大流)
题目大概说有m个人要过一条宽W的河,人最远跳远距离是d,河上有n个垃圾堆,每个垃圾堆都有坐标和同一时间能容纳的人数,问所有人最少要跳几次才能跳到对岸. 又是一题根据时间拆点的最大流. 二分时间建容量网 ...
- objective-c 条件运算符
条件运算符 val1!=0 ? val1:val2 等价于 val1?val2
- JAVA生成RSA非对称型加密的公钥和私钥(利用JAVA API)
非对称型加密非常适合多个客户端和服务器之间的秘密通讯,客户端使用同一个公钥将明文加密,而这个公钥不能逆向的解密,密文发送到服务器后有服务器端用私钥解密,这样就做到了明文的加密传送. 非对称型加密也有它 ...
- 【C语言】12-指向一维数组元素的指针
一.用指针指向一维数组的元素 1 // 定义一个int类型的数组 2 int a[2]; 3 4 // 定义一个int类型的指针 5 int *p; 6 7 // 让指针指向数组的第0个元素 8 p ...
- JAVA String.format 方法使用介绍
1.对整数进行格式化:%[index$][标识][最小宽度]转换方式 我们可以看到,格式化字符串由4部分组成,其中%[index$]的含义我们上面已经讲过,[最小宽度]的含义也很好理解, ...