English 中文(简体)
设在利克斯的网络服务处的员额形象档案
原标题:Post image file to RESTful Web Service

我试图向一个网络服务机构发送图像文件。

我的守则如下:

   ConnectionFactory connFact = new ConnectionFactory();
        ConnectionDescriptor connDesc;

        //String value = new String(data);
        String value= Base64OutputStream.encodeAsString(data, 0, data.length, false, false);

        value = "imgData=" + value;

        connDesc = connFact.getConnection("http://localhost:50806/Send");
        int iResponseCode = 0;
        HttpConnection httpConn = null;
        OutputStream os = null;
        if (connDesc != null)
        {

            try
            {
             byte[] theByteArray = value.getBytes();

                httpConn = (HttpConnection)connDesc.getConnection();

                httpConn.setRequestProperty("Content-Type", "image/jpeg");
                httpConn.setRequestMethod(HttpConnection.POST);
                httpConn.setRequestProperty("Content-Disposition", "form-data");
                httpConn.setRequestProperty("Connection", "Keep-Alive");
                httpConn.setRequestProperty("Content-Length", String.valueOf(data.length));

                //os = httpConn.openOutputStream();
                //os.write(theByteArray);
                DataOutputStream printout = new DataOutputStream (httpConn.openOutputStream()); 
                printout.write(theByteArray);
                iResponseCode = httpConn.getResponseCode();        
             } 
            catch(Exception e){
                e.printStackTrace();
            }
            finally{
                if(os != null)
                    os.close();

                if(httpConn != null){                    
                 httpConn.close();
                }
            }

        }
  return Integer.toString(iResponseCode);  

一种星体表示,图像档案已输入该方法。

服务签署:

   [AcceptVerbs(HttpVerbs.Post)]  
    public ActionResult Send(string imgData)
    {}

任何关于如何发出这种看法的想法?

Thanks so much, Dan

最佳回答

基地64号编码的座标可能太大,无法在GET申请中作为URL参数通过。 无论是该装置还是某种代理方式,都可能与请求不符。 采用长期合作行动倡议的要求,这将更加安全。 为此,将请求定为一份载有<条码>的持久性有机污染物(http://www.un.org/Depts/dpa/index.htm>的持久性有机污染物(http://www.un.org/chinese/sc/presidency.htm)的持久性有机污染物清单。 (可能的话,PostData 。)

问题回答

暂无回答




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签