C# 如何在xamarin.ios的body中使用post方法加载web视图?
我想在加载web视图时将我的objective-c代码转换为xamarin.ios中的c#无法与服务器进行通信web视图显示为空白屏幕 目标c代码:C# 如何在xamarin.ios的body中使用post方法加载web视图?,c#,ios,iphone,xamarin.ios,xamarin.forms,C#,Ios,Iphone,Xamarin.ios,Xamarin.forms,我想在加载web视图时将我的objective-c代码转换为xamarin.ios中的c#无法与服务器进行通信web视图显示为空白屏幕 目标c代码: NSData *myRequestData = [NSData dataWithBytes: [encryptedStr UTF8String] length: [encryptedStr length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithUR
NSData *myRequestData = [NSData dataWithBytes: [encryptedStr UTF8String] length: [encryptedStr length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: urlAsString]];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setValue:urlAsString forHTTPHeaderField:@"Referer"];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: myRequestData];
NSLog(@"HTTPBody:%@",request.HTTPBody);
NSLog(@"myRequestData:%@",myRequestData);
[_viewWeb loadRequest:request];
//This is how i converted above objective-c code to the c# code for xamarin.ios
NSString pathurl = new NSString(AppConstants.TRANS_URL);
pathurl = pathurl.CreateStringByAddingPercentEscapes(NSStringEncoding.ISOLatin1);
NSUrl urls = NSUrl.FromString(pathurl);
byte[] st2 = System.Text.Encoding.UTF8.GetBytes(postparam);
// Initialize unmanaged memory to hold the array.
int size = Marshal.SizeOf(st2[0]) * st2.Length;
IntPtr pnt = Marshal.AllocHGlobal(size);
try
{
// Copy the array to unmanaged memory.
Marshal.Copy(st2, 0, pnt, st2.Length);
// Copy the unmanaged array back to another managed array.
byte[] managedArray2 = new byte[st2.Length];
Marshal.Copy(pnt, managedArray2, 0, st2.Length);
Console.WriteLine("The array was copied to unmanaged memory and back.");
}
finally
{
// Free the unmanaged memory.
Marshal.FreeHGlobal(pnt);
}
NSData myRequestData = NSData.FromBytes(pnt,(nuint) postparam.Length);
var dictionnary = NSDictionary.FromObjectAndKey(new NSString(AppConstants.TRANS_URL), new NSString("Referer"));
var req = new NSMutableUrlRequest(urls);
req["Content-Type"] = "application/x-www-form-urlencoded charset=utf-8";
req.HttpMethod = "POST";
req.Headers = dictionnary;
webView.LoadRequest(req);
我无法与服务器通信并加载web视图
先谢谢你