我刚刚开始使用SagePay下拉表格替换我们网站上当前付款流程的任务。页面加载的第一部分是从Sagepay生成会话密钥(持续400秒)。他们在网站上给出的curl命令示例使用我们的API密钥和密码进行工作,如下所示:-
curl https://pi-test.sagepay.com/api/v1/merchant-session-keys \
-H "Authorization: Basic aEpZeHN3N0hMYmo0MGNCOHkxodUo4RzU0TzZyRHBVWHZFNmhZRHJyaWE6bzJpSFNyRnliWU1acG1XT1FNdWhzWFA1MlY0ZkJ0cHVTRHNocktEU1dzQlkxT2lONmh3ZDlLYjEyejRqNVVzNXU=" \
-H "Content-type: application/json" \
-X POST \
-d '{
"vendorName": "ourvendorname"
}'
上面发送的基本授权是apikey:apipassword的base64编码。 (以上只是示例)。
所以他们也有一个php示例,但是我试图在vb.net中完成此操作。在几个站点上,我整理了以下内容:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Web" %>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load()
Dim myReq As HttpWebRequest
Dim myResp As HttpWebResponse
Dim myData As String = "{""vendorName"": ""ourvendorname""}"
'Response.Write(myData)
myReq = HttpWebRequest.Create("https://pi-live.sagepay.com/api/v1/merchant-session-keys")
myReq.Method = "POST"
myReq.ContentType = "application/json"
myReq.Headers.add("Authorization", "Basic " & Convert.ToBase64String(Encoding.UTF8.GetBytes("ourapikey:ourapipassword")))
myReq.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData), 0, System.Text.Encoding.UTF8.GetBytes(myData).Count)
myResp = myReq.GetResponse
Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)
Dim myText As String
myText = myreader.ReadToEnd
End Sub
</script
但是,此操作失败并显示以下内容:-
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
编译器错误消息:BC30456: 'Count' is not a member of 'System.Array'.
源错误:
Line 24: myReq.ContentType = "application/json"
Line 25: myReq.Headers.add("Authorization", "Basic " & Convert.ToBase64String(Encoding.UTF8.GetBytes("base64encodedversionofapikey:apipassword")))
Line 26: myReq.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData), 0, System.Text.Encoding.UTF8.GetBytes(myData).Count)
Line 27:
Line 28: myResp = myReq.GetResponse
Source File: C:\xxxxxxx\new.aspx Line: 26
我已经读过,是的.count在.net 2.0下不是system.array的成员,并且它在3.5以下,我已将应用程序池更改为.net 4.0,但仍然没有骰子。如果您导入system.linq,我也已经读过了,这将解决错误,仍然是相同的错误。我最后读到,需要使用.length而不是.count,但是网页只是挂起并且超时没有错误。我尝试放置一个值来替换字节流的结束值(小于实际长度)仍然挂起。
我没主意了,所以来这里吧...
我已经将变量mydata输出到控制台,并且按照其网站的格式正确显示了。
感谢阅读。