小编Cru*_*633的帖子

Ruby未定义的方法`bytesize'用于#<Hash:0x2954fe8>

我有以下Ruby代码,用于沙盒模式的跟踪网站:

require "net/http"
require "net/https"
require "uri"

xml = <<XML
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><data appname="dhl_entwicklerportal" language-code="de" password="Dhl_123!" request="get-status-for-public-user"><data piece-code="00340433836536550280"></data></data>
XML

uri = URI('https://cig.dhl.de/services/sandbox/rest/sendungsverfolgung')

nhttp = Net::HTTP.new(uri.host, uri.port)
nhttp.use_ssl=true
nhttp.verify_mode=OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri)
request.basic_auth 'xpackageWP', 'hidden'
response = nhttp.start {|http|
http.request(request, xml:xml)
}

puts response.body
Run Code Online (Sandbox Code Playgroud)

我总是得到错误:

d:/Ruby200/lib/ruby/2.0.0/net/http/generic_request.rb:179:in `send_request_with_body' undefined method `bytesize' for #<Hash:0x2954fe8> (NoMethodError)
from d:/Ruby200/lib/ruby/2.0.0/net/http/generic_request.rb:130:in `exec'
from d:/Ruby200/lib/ruby/2.0.0/net/http.rb:1404:in `block in transport_request'
from d:/Ruby200/lib/ruby/2.0.0/net/http.rb:1403:in `catch'
from d:/Ruby200/lib/ruby/2.0.0/net/http.rb:1403:in `transport_request'
from d:/Ruby200/lib/ruby/2.0.0/net/http.rb:1376:in `request'
from D:/Dropbox_5BHIF/Dropbox/TempDHL/Main.rb:17:in `block in <main>'
from d:/Ruby200/lib/ruby/2.0.0/net/http.rb:852:in `start'
from D:/Dropbox_5BHIF/Dropbox/TempDHL/Main.rb:16:in …
Run Code Online (Sandbox Code Playgroud)

ruby net-http

15
推荐指数
1
解决办法
3万
查看次数

从C#中的Bing Map API解析JSON代码

我使用Bing Map REST API,因为我想从一个独立的位置找出地理定位.Url工作得很好,但由于事实,我第一次使用JSON代码,我真的不知道我是如何得到我想要的输出.

我尝试了以下方法:

string URL = "http://dev.virtualearth.net/REST/v1/Locations?countryRegion=&adminDistrict=&locality=Wien&postalCode=&addressLine=&userLocation=&userIp=&usermapView=&includeNeighborhood=&maxResults=&key=MY_KEY";
WebClient client = new WebClient();
client.OpenReadAsync(new Uri(URL, UriKind.Absolute));
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);

private void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Point));
    Point data = serializer.ReadObject(e.Result) as Point;
}

[DataContract]
public class Point
{
    /// <summary>
    /// Latitude,Longitude
    /// </summary>
    [DataMember(Name = "coordinates")]
    public double[] Coordinates { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中输入链接时,这是我的回复:

{"authenticationResultCode":"ValidCredentials","brandLogoUri":"http://dev.virtualearth.net/Branding/logo_powered_by.png","copyright":"Copyright©2013 Microsoft及其供应商.保留所有权利.未经Microsoft Corporation明确书面许可,不得访问API且不得以任何方式使用,复制或传播内容和任何结果.","resourceSets":[{"estimatedTotal":1,"resources":[{" __type ":" 位置:http://schemas.microsoft.com/search/local/ws/rest/v1" , "BBOX":47.253395080566406,-123.16571807861328,47.946159362792969,-121.50344085693359], "名":"西雅图, WA", "点":{ "类型": "点", "坐标":[47.603561401367188,-122.32943725585938]},"地址":{"adminDistrict":"WA","adminDistrict2":"King Co.","countryRegion":"United States","formattedAddress":"Seattle,WA","locality": "西雅图"}, …

c# json bing-maps

4
推荐指数
1
解决办法
5239
查看次数

在heredoc中使用变量

如何在heredoc中使用Ruby变量?例如:

<<XML
  <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><data password="topsecret"></data>
XML
Run Code Online (Sandbox Code Playgroud)

如何使用Ruby变量设置密码?

ruby

-1
推荐指数
1
解决办法
560
查看次数

标签 统计

ruby ×2

bing-maps ×1

c# ×1

json ×1

net-http ×1