![](/img/trans.png)
[英]Retrieving Json data from same domain, how to use JsonP to get from another domain with asp.NET?
[英]How to get JSON back from HTTP POST Request (to another domain)
我正在尝试在网站上使用API,这是手册的一部分:
经过身份验证的会话 (摘自此处 )
要创建经过身份验证的会话,您需要从'/ auth'API资源请求authToken。
额外数据:“authToken”cookie和标头,包含应该用于后续调用的身份验证令牌。
参数:用户名/密码
POST / auth HTTP / 1.1
接受:application / xml
内容类型:application / x-www-form-urlencoded
用户名= my_username&密码= MY_PASSWORD
HTTP / 1.1 200 OK Set-Cookie:authToken = 1KVARbypAjxLGViZ0Cg + UskZEHmqVkhx / Pm ......;
authToken:1KVARbypAjxLGViZ0Cg + UskZEHmqVkhx / PmEvzkPGp ... ==
Content-Type:application / xml; 字符集= UTF-8
我如何让它工作?
我尝试过jQuery,但它似乎与XSS有关。 实际的代码片段将不胜感激。
我所寻找的只是C#中的WebClient类
您需要将application / json放在Accept标头中,这告诉服务器您希望它以该格式响应 - 而不是xml。
我正在使用rails从stage.amee.com/auth中提取相同的身份验证令牌cookie,如上所述。 在我创建并自定义返回200 OK的正确请求对象之前,需要进行一些实验,并将authtoken作为cookie。 我还没有找到一种有效的方法来读取请求对象,或者我会发布它看起来的确切内容。 这是我的应用程序控制器的ruby代码
#define parameters
uri=URI.parse('http://stage.amee.com')
@path = '/auth'
@login_details = 'username=your_username&password=your_password'
@headers = {'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'}
#create request object
req = Net::HTTP.new(uri.host, uri.port)
#send the request using post, defining the path, body and headers
resp, data = req.post(@path, @login_details, @headers)
#print response details to console
puts "response code = " << resp.code
puts "response inspect = " << resp.inspect
resp.each do |key, val|
puts "response header key : " + key + " = " + val
end
puts "data: " + data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.