Swift base64图像Asp.net Soap webservice上传问题

时间:2016-02-01 09:48:46

标签: ios asp.net swift web-services soap

我想将图片上传到我的肥皂网服务,但它无效。

这是我在swift 的上传方法,如果错误== nil {}此部分永远无效我认为它不是服务请求我如何使用try catch来使用此代码

    let imageData = UIImageJPEGRepresentation(selected_image,1.0);
    let post_url:NSURL = NSURL(string : "http://awebsite.com/engine.asmx")!

     let base64String = imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0));

    var soapBody:String = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
    soapBody += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
    soapBody += "<soap:Body><ArizaKayitResim xmlns=\"http://awebsite.com\">";
    soapBody += "<key>123456</key>";
    soapBody += "<kayitNo>\(kayitNo)</kayitNo>";
    soapBody += "<base64>\(base64String)</base64>";
    soapBody += "</ArizaKayitResim>";
    soapBody += "</soap:Body>";
    soapBody += "</soap:Envelope>";

    let soapBodyLength = soapBody.characters.count;

    let request = NSMutableURLRequest(URL: post_url);


    request.HTTPMethod = "POST";
    request.HTTPBody = soapBody.dataUsingEncoding(NSUTF8StringEncoding);

    request.addValue("http://awebsite.com", forHTTPHeaderField: "Host");
    request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type");
    request.addValue("\(soapBodyLength)", forHTTPHeaderField: "Content-Length")
    request.addValue("http://awebsite.com/ArizaKayitResim", forHTTPHeaderField: "SOAPAction");

    let task = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { data, response, error ->
                    Void in

                if error == nil
                {

                }
                else
                {



                    }



            })
            task.resume();

0 个答案:

没有答案