使用rest发送多篇文章 [英] send a multipart post using rest

查看:72
本文介绍了使用rest发送多篇文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已使用以下代码通过多篇文章发送文件,并且得到的响应代码为500 pl,告诉我我的代码有什么问题

Hi

I have used the following code to send the file using multipart post and i am getting the responsecode as 500 pl tell me what is wrong in my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CodeScales.Http;
using CodeScales.Http.Methods;
using CodeScales.Http.Entity;
using CodeScales.Http.Entity.Mime;
using CodeScales.Http.Common;
using System.IO;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpClient ht = new HttpClient();
        HttpClient client = new HttpClient();
        HttpPost postMethod = new HttpPost(new Uri("http://www.inspire-geoportal.eu/INSPIREValidatorService/resources/validation/inspire"));
        postMethod.Headers.Add("Authorisation", "text/html");
        MultipartEntity multipartEntity = new MultipartEntity();
        FileInfo fileInfo = new FileInfo(@"C:\Users\10033\Desktop\WebService\Metadata_test_Inspire_DM_MedYttäckning _och_Överensst_true_ISO19139.xml");
        FileBody fileBody = new FileBody("Metadata_test_Inspire_DM_MedYttäckning _och_Överensst_true_ISO19139", "Metadata_test_Inspire_DM_MedYttäckning _och_Överensst_true_ISO19139.xml", fileInfo);
        StringBody stringBody = new StringBody(Encoding.UTF8, "Metadata_test_Inspire_DM_MedYttäckning _och_Överensst_true_ISO19139.xml", "text/html");
        multipartEntity.AddBody(stringBody);
        postMethod.Entity = multipartEntity;
        multipartEntity.IsChunked = true;
        postMethod.Entity.IsChunked = true;
        //multipartEntity.AddBody(fileBody);
        CodeScales.Http.Methods.HttpResponse response = client.Execute(postMethod);
        Response.Write(EntityUtils.ToString(response.Entity));
        Console.WriteLine("Response Code: " + response.ResponseCode);
        Console.WriteLine("Response Content: " + EntityUtils.ToString(response.Entity));
    }
}

推荐答案

响应代码500表示" InternalError ".这意味着REST服务中出现了异常.

尝试在"提琴手"中调用REST服务,它可能会为您提供一些其他错误详细信息.
http://www.fiddler2.com/fiddler2/
Response Code 500 represents "InternalError". That means something has exception out from your REST Service.

Try by calling your REST Service in "Fiddler", it may provide you some additional Error Details.
http://www.fiddler2.com/fiddler2/


这篇关于使用rest发送多篇文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆