[英]How to get response from API after POST
我正在與一個API交互,有時會返回某些功能的參考號。 我將如何顯示此參考號。 目前,API返回例如此字符串(出於安全原因刪除了一些代碼)。
if (AppSettings.GetLandingPageReceipts())
{
long returnValue = loanLP.AddWithdrawalToBankID(CustomerID, SavingsAccountID, BankAccID, Amount);
return string.Concat("Requested Withdrawal Ref No: ", returnValue);
}
ReceiptWithdrawal withdraw = new ReceiptWithdrawal(CustomerID, SavingsAccountID, Amount, session, pp, BankAccID);
ReceiptTRN TRN = new ReceiptTRN();
TRN.Post(withdraw);
return JsonConvert.SerializeObject(withdraw.ReceiptNo);
在Ruby代碼中,我將此用於Post調用
def post_call(routePath, params)
started_at = Time.now
logger.bench 'SERVICE - POST', started_at, routePath
uri = URI.parse("#{settings.abacus_service_endpoint}#{routePath}")
http = Net::HTTP.new(uri.host, uri.port)
http.set_debug_output $stderr
req = Net::HTTP::Post.new(uri.request_uri,get_header_for_abacus_service)
req.form_data = params
resp = http.request(req)
if response_ok?(resp)
if @errors
puts '======= post request form_data ======='
puts params
puts '==================='
end
return resp
end
end
在本地工作時,我可以在控制台中看到以下內容,因此我知道它已通過。 它只是訪問它就是問題。
opening connection to 10.10.10.27...
opened
<- "POST /Accounts/WithdrawalToBank HTTP/1.1\r\nAuthorization: Token 433\r\nX-Customer-Id: 433\r\nX-Customer-Pin: 8EFD155E7C829421E16F14D367568C4179C4548320CD7E1B6AD6E9A485F2AF092FA42D0F645085F3DBBA5AEC2434720FC76E407E41443C3F5EDAFB958793254A\r\nX-Ip-Address: 10.0.2.2\r\nAccept: */*\r\nUser-Agent: Ruby\r\nContent-Type: application/x-www-form-urlencoded\r\nConnection: close\r\nHost: 10.10.10.27:3579\r\nContent-Length: 81\r\n\r\n"
<- "CustomerID=433&SavingsAccountID=10922&BankAccountID=2450&Amount=10.00&Reference=a"
-> "HTTP/1.1 200 OK\r\n"
-> "Transfer-Encoding: chunked\r\n"
-> "Content-Type: text/html\r\n"
-> "Server: Microsoft-HTTPAPI/2.0\r\n"
-> "Date: Mon, 23 Nov 2015 11:03:02 GMT\r\n"
-> "Connection: close\r\n"
-> "\r\n"
-> "22\r\n"
reading 34 bytes...
-> "Requested Withdrawal Ref No: 10059"
read 34 bytes
reading 2 bytes...
-> "\r\n"
read 2 bytes
-> "0\r\n"
-> "\r\n"
Conn close
如果需要任何其他信息,請告訴我。
如果API返回的是正文,您應該可以通過resp.body
從響應中resp.body
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.