![](/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.