2
我對Xamarin Studio非常新穎。我需要在我的代碼中使用一個功能,這是我在Objective C中編寫的代碼,來自之前在Xamarin(C#)中編寫的代碼。目標C中的Xamarin Studio的類HttpWebRequest替換是什麼?
在Xamarin代碼中,圖像的字節流正在附加到HttpWebRequest實例。併發布到服務器上,以獲得處理後的圖像。
我暫時無法找到如何在xamarin
using (Stream requestStream = httpWebRequest.GetRequestStream()){}
確實使用相同的功能代碼。
我Xamarin代碼如下: -
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create (string.Concat (new string[]
{
Common.BaseAddress,
"visualize/",
GenericHelper.ServiceEncrypt (Common.Token),
"/",
Common.AppTag,
"/",
Common.ConstructTreatmentSelections()
}));
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
int num = 2048;
int i = 1;
int num2 = pBytePhotoImage.Length;
while (i < num2)
{
if (i + num > num2)
{
num = num2 - i;
}
requestStream.Write (pBytePhotoImage, i - 1, num);
float fProgress = (float)i/(float)num2;
if (fProgress <= 1f)
{
nSAutoreleasePool.InvokeOnMainThread (delegate
{
pProgressBar.set_Progress (fProgress);
});
}
else
{
nSAutoreleasePool.InvokeOnMainThread (delegate
{
pProgressBar.set_Progress (1f);
});
}
i += num;
}
nSAutoreleasePool.InvokeOnMainThread (delegate
{
pAnimationImage.StartAnimating();
});
}
從搜索在互聯網上有什麼我可以收集和實施是: -
我的目標C代碼如下: -
NSData *data = UIImageJPEGRepresentation(self.imageView.image, 0.2);
NSString *webServiceURL = @"https://webserviceNameBaseAddress/visualize/lEr0WKCdarv2FLGFvBRbhs41FN7zhgcdiwuEqFtLQINJ|PQpM8HEGQ~~/ios/SL|VL|OC|ML|";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:webServiceURL]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:data];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData * responseData, NSError *err) {
NSLog(@"URL Response");
if (err) {
NSLog(@"Err %@",err.description);
}else
{
if (responseData) {
NSLog(@"%@",[UIImage imageWithData:responseData]);
}
else{
NSLog(@"not returning anything");
}
}
}];
現在,當我運行在Xcode代碼: 輸出是: -
Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x75a9ea0 {NSUnderlyingError=0x7189250 "bad URL", NSLocalizedDescription=bad URL}
任何幫助將是偉大的。 自兩天以來,我一直堅持這一點。
PS: - 提取的POST請求的web服務的URL,從Xamarin應用程序代碼。 我所做的是 我已經打印的URL字符串出與Consol.WriteLine()在Xamarin 的幫助下,然後用精確的輸出在Xcode作爲NSMutableURLRequest
這是IOS安全。也許這可以幫助您http://stackoverflow.com/questions/6287230/bad-url-when-requesting-with-nsurl或http://stackoverflow.com/questions/10782591/nsurlerrordomain-code-1000-bad-url-什麼 - 它真的意味着 –
我不明白什麼是工作,什麼不是。 ObjC版本是好的,但C#版本不是?或相反亦然?如果你在Xcode中出現錯誤,你顯然不會使用Xamarin--我很困惑。 – Krumelur
他想將C#代碼轉換爲ObjC。這是很難確定什麼是錯誤的,因爲不是所有的代碼是可用的。這是您要訪問的服務器地址:「webserviceNameBaseAddress」 – SKall