【转】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 ...
随机推荐
- 垂直的SeekBar:VerticalSeekBar
public class VerticalSeekBar extends AbsSeekBar { private Drawable mThumb; public interface OnSeekBa ...
- LR结构图
- Class文件结构
各种不同平台的虚拟机与所有平台都统一使用的程序存储格式--字节码(ByteCode)是构成平台无关性的基石,除了平台无关性,虚拟机的另外一种中立特性--语言无关性正越来越被开发者所重视.在Java发展 ...
- 学习NGUI前的准备NGUI的相关信息
学习NGUI前的准备NGUI的相关信息 第1章 学习NGUI前的准备 NGUI是Unity最重要的插件,在Unity资源商店(Asset Store)的付费排行榜中始终名列前茅,如图1-1所示.本章 ...
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- html成绩单表格
<!DOCTYPE html> <html> <head> <meta name="generator" content="HT ...
- python 代码片段15
#coding=utf-8 ''' 如果运行时发生异常的话,解释器会查找相应的处理函数.要是在当前函数里没有 找到的话,它会将异常传递给上层的调用函数,看看那里能不能处理.如果在在最 外层还没有找到的 ...
- sql server 取随机行
--从table_name中随机取n行 select top n * from table_name order by NEWID()
- Eclipse @override报错解决
第一种解决方案: @Override是JDK5 就已经有了,但有个小小的Bug,就是不支持对接口的实现,认为这不是Override 而JDK6 修正了这个Bug,无论是对父类的方法覆盖还是对接口的实现 ...
- QPushButton 与 QListWidget 的按键响应
在Qt中添加按钮或表格控件时需要添加其按键响应,一般来说有两种方法,一种是直接实现其响应函数,第二种是自己写一个响应函数,然后用Qt的信号槽将它们连接起来.愚以为第一种方法更为简单一些. 声明这些控件 ...