我做jQuery中下面的調用,使用JSONP作爲我的數據格式,我想直接做在Silverlight:
$.getJSON('https://api.wordstream.com/authentication/login?callback=?',
{ 'username': un,
'password': pw
}, function (loginResults) {
API_SESSION_ID = loginResults['data']['session_id'];
$.getJSON('https://api.wordstream.com/keywordtool/get_keywords?callback=?',
{ 'session_id': API_SESSION_ID,
'seeds': keyword,
'max_results': 20
}, function (keywordResults) {
for (i = 0; i < +keywordResults['data'].length; i++) {
Keywords[i] = keywordResults['data'][i][0];
}
return(Keywords);
});
});
我想這樣的事情辦理第一$ .getJSON(認證&回我的身份驗證令牌):
WebClient downloader = new WebClient();
WebRequest.RegisterPrefix("https://", System.Net.Browser.WebRequestCreator.ClientHttp);
var client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
client.UseDefaultCredentials = false;
client.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(loginEndpoint);
當我嘗試和運行此我得到我downloadstringcompleted事件處理程序中出現以下錯誤:
{System.Security.SecurityException: Security error.
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__1(Object sendState)}
我以前通過.asmx文件在EF & SOAP服務中使用了WCF Ria服務,所以我對Web服務的想法並不陌生。我不確定是否需要使用clientaccesspolicy或跨域文件。
關於如何進行的任何想法?
感謝, 斯科特
我只是希望你不發送'password'以純文本形式在網上... – balexandre
注意使用RegisterPrefix爲https。所以不要明文。 –
仍然應該首先編碼,而不是正常的text.Plus,在處理實現'IDisposable'接口的方法時總是使用'using()'。 – balexandre