我遇到了同样的问题,我建立的唯一解决方案是实现一个 Phonegap 插件。
这是我使用的 C# 代码:
namespace WPCordovaClassLib.Cordova.Commands
{
[DataContract]
public class PhonegapWindowsPhonePostObject
{
[DataMember(IsRequired = false, Name = "yourParamName1")]
public string yourParam1;
[DataMember(IsRequired = false, Name = "yourParamName2")]
public string yourParam2;
}
public class PhonegapWindowsPhonePost: BaseCommand
{
public void post(string options)
{
PhonegapWindowsPhonePostObject pwppo = JSON.JsonHelper.Deserialize<PhonegapWindowsPhonePostObject>(options);
try
{
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var data = "YOUR DATA STRING HERE"; //use the pwppo object to retrieve your parameters
var url = "URL OF THE SERVICE HERE";
WebClient wc = new SharpGIS.GZipWebClient();
var URI = new Uri(url);
wc.Encoding = Encoding.UTF8;
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc__UploadStringCompleted);
wc.UploadStringAsync(URI, "POST", data);
});
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
void wc__UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
try
{
if (e.Result != null)
this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, e.Result));
else
this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error 401"));
}
catch (Exception ex)
{
this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message));
// no http status code available
}
}
}
}
这是从您的应用程序调用插件的 Javascript 代码:
function loginToWebService(yourParam1, yourParam2) {
var options = { "yourParamName1": yourParam1, "yourParamName2": yourParam2};
cordova.exec(success, error,"PhonegapWindowsPhonePost","post", options);
}
我希望它会帮助你。
注意:Phonegap 2.8 版本并没有解决与发行说明相反的问题...
再见 !