2016-09-23 4 views
2

POSIAN을 사용하여 문자열 배열을 웹 API에 보냅니다. 여기 우체부를 사용하여 배열을 보내는 방법에 대한이 SO post을 보았다 POSTMAN을 사용하여 문자열 배열을 게시하는 방법은 무엇입니까?

[HttpPost] 
    public async Task<IEnumerable<DocumentDTO>> GetDocuments([FromBody]IEnumerable<string> documentNames) 
    { 
     return await _service.GetDocuments(documentNames); 
    } 

같은 웹 API 방법을 찾습니다. 그래서 여기에 내가 배열을 보낸다 방법 enter image description here

피들러 보여줍니다 요청의 콘텐츠 형식은 multipart/form-data;

enter image description here

입니다하지만 난

{ "메시지"와 같은 오류 응답을 얻고있다 :는 "이 요청 엔터티의 미디어 유형 'multipart/form-data' 이이 리소스에 대해 지원되지 않습니다. ","ExceptionMessage ":"No MediaTypeFormatter를 사용할 수 있습니다. E는 '는 IEnumerable 1' from content with media type 'multipart/form-data'.", "ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
"StackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable
1 포매터 IFormatterLogger formatterLogger, CancellationToken cancellationToken) \ R \ n System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync에서 (HttpRequestMessage 요청 타입 타입 IEnumerable`1 포맷터 유형의 객체를 읽을 , IFormatterLogger formatterLogger, CancellationToken cancellationToken) "}

I가 documentNames, documentNames[]으로 키 설정 시도

, I는 x-www-form-urlencoded로 본문을 선택 시도 documentNames[0]
. API를 사용하면 빈 콜렉션을받습니다.
본문을 선택하려고했습니다. raw API가 null을 매개 변수로받는 경우.

질문
1
> 어떻게 폼 데이터를 사용하여 문자열 배열을 보내려면 어떻게합니까?
1> x-www-form-urlencoded를 사용하여 문자열 배열을 보내려면 어떻게해야합니까? ?
2> 문자열 배열을 원시 json으로 보내려면 어떻게해야합니까?

답변

6

JSON 배열로 전달하고 API의 메소드 서명

public void Post([FromBody] IEnumerable<string> value) 
    { 
     //some processing 
    } 
를 들어 아래

enter image description here

같은 raw 옵션을 선택

관련 문제