【转】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 ...
随机推荐
- isnull的使用方法
is null 查看列数据为空 select*from lrb where lrid is null ISNULL使用指定的替换值替换 NULL. 语法ISNULL ( check_express ...
- Winedt打开tex文件报错error reading的解决方案
我刚装就发现winedt打开一些.tex文件时会出现reading error,然后看不到任何文字(网上有人讨论打开是乱码的问题,但是我的是完全看不到任何东西),我的系统winxp,网上有人说好像是和 ...
- html 绘图渐变和图片填充
包括线性渐变和径向渐变 <!DOCTYPE html> <html> <head lang="en"> <meta charset=&qu ...
- 2016 Multi-University Training Contest 8
solved 4/11 2016 Multi-University Training Contest 8 贪心 1001 Ball(BH) 代码: #include <bits/stdc++.h ...
- Codeforces 176B (线性DP+字符串)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28214 题目大意:源串有如下变形:每次将串切为两半,位置颠倒形成 ...
- 洛谷 P1010 幂次方 Label:模拟
题目描述 任何一个正整数都可以用2的幂次方表示.例如 137=2^7+2^3+2^0 同时约定方次用括号来表示,即a^b 可表示为a(b). 由此可知,137可表示为: 2(7)+2(3)+2(0) ...
- 配置当前用户使用豆瓣pip源
配置当前用户使用豆瓣pip源 mkdir ~/.pip/ cat ~/.pip/pip.conf [global] index-url = http://pypi.douban.com/simpl ...
- HttpRuntime.Cache的使用经验
配置文件 <appSettings> <add key="EnableCache" value="true"/> "/ ...
- kvm快照
Kvm快照: 1.基于lvm的快照 2.kvm自带的快照功能(需要qcow2 磁盘文件才支持快照) 关闭kvm虚拟机: 查看磁盘文件信息: [root@super67 ~]# qemu-img inf ...
- javascript获取随机rgb颜色和十六进制颜色的方法
<div id="console">在线交易平台的成功秘诀:从 Ebay 到 Yelp 到 Uber</div> <script type=" ...