【转】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 ...
随机推荐
- android 广播
关于广播以前感觉是一知半解的,这次看到同事整理的文档,顺带跟着再参考几篇博文也学习整理了下,先上个整理的图 代码模板 发送广播 public static final String RECEIVE_A ...
- 安装完最小化 RHEL/CentOS 7 后需要做的 30 件事情(五)
25. 安装 Linux Malware Detect (LMD) Linux Malware Detect (LMD) 是 GNU GPLv2 协议下发布的开源 Linux 恶意程序扫描器,它是特别 ...
- flume与Mosquitto的集成
文章来自:http://www.cnblogs.com/hark0623/p/4173714.html 转发请注明 因业务需求,需要flume收集MQTT(Mosquitto)的数据. 方法就是 ...
- 用c++处理文件流
#include<bits/stdc++.h> using namespace std; struct Bian { int num; string name; }b[]; int mai ...
- vim 全局替换命令
语法 :[addr]s/源字符串/目的字符串/[option] :%s/源字符串/目的字符串/c 全局替换命令为: :%s/源字符串/目的字符串/g [add ...
- Bitnami Redmine安装和插件配置
公司要进行敏捷开发管理,最后选择Redmine作为管理工具. 而Redmine本身的安装非常麻烦,要安装mysql,ruby,redmine,apach. 显然这不是一个偷懒的人应该做的,最后找到Bi ...
- java 文件md5+字符串md5 实现
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; impo ...
- BZOJ3780 : 数字统计
从低位到高位数位DP,f[i][j][k]表示已经填了后i位,转化的数字为j,后i位与x后i位的大小关系为k的方案数. #include<cstdio> const int N=202,B ...
- HDU 4057 Rescue the Rabbit(AC自动机+DP)
题目链接 一个数组开小了一点点,一直提示wa,郁闷,这题比上个题简单一点. #include <iostream> #include <cstring> #include &l ...
- 泛型,动态创建List<T> (转摘)
第一种: static void Main() { object intList = MakeList(typeof(int), 1, 2, 3); ...