mirror of
https://github.com/foss42/apidash.git
synced 2025-05-24 09:46:45 +08:00
fixes
This commit is contained in:
@ -101,7 +101,7 @@ class Codegen {
|
||||
case CodegenLanguage.cCurlCodeGen:
|
||||
return CCurlCodeGen().getCode(rM);
|
||||
case CodegenLanguage.cSharpHttpClient:
|
||||
return CSharpHttpClientCodeGen().getCode(rM, boundary: boundary);
|
||||
return CSharpHttpClientCodeGen().getCode(rM);
|
||||
case CodegenLanguage.cSharpRestSharp:
|
||||
return CSharpRestSharp().getCode(rM);
|
||||
case CodegenLanguage.phpHttpPlug:
|
||||
|
@ -78,13 +78,13 @@ using (var request = new HttpRequestMessage(HttpMethod.{{ method | capitalize }}
|
||||
}
|
||||
''';
|
||||
|
||||
String? getCode(RequestModel requestModel, {String? boundary}) {
|
||||
String? getCode(RequestModel requestModel) {
|
||||
try {
|
||||
StringBuffer result = StringBuffer();
|
||||
|
||||
// Include necessary C# namespace
|
||||
String formdataImport = requestModel.hasFormData //
|
||||
? (requestModel.hasFileInFormData ? "multipart" : "urlencoded")
|
||||
String formdataImport = requestModel.hasFormData
|
||||
? "multipart" //(requestModel.hasFileInFormData ? "multipart" : "urlencoded")
|
||||
: "nodata";
|
||||
result.writeln(jj.Template(kTemplateNamespaces).render({"formdata": formdataImport}));
|
||||
|
||||
@ -116,10 +116,11 @@ using (var request = new HttpRequestMessage(HttpMethod.{{ method | capitalize }}
|
||||
"mediaType": requestModel.requestBodyContentType.header,
|
||||
}));
|
||||
} else if (requestModel.hasFormData) {
|
||||
final String renderingTemplate = requestModel.hasFileInFormData
|
||||
? kTemplateMultipartFormDataContent //
|
||||
: kTemplateFormUrlEncodedContent;
|
||||
// final String renderingTemplate = requestModel.hasFileInFormData
|
||||
// ? kTemplateMultipartFormDataContent
|
||||
// : kTemplateFormUrlEncodedContent;
|
||||
|
||||
final String renderingTemplate = kTemplateMultipartFormDataContent;
|
||||
result.writeln(jj.Template(renderingTemplate).render({
|
||||
"formdata": requestModel.formDataMapList,
|
||||
}));
|
||||
|
@ -361,20 +361,19 @@ using (var request = new HttpRequestMessage(HttpMethod.Post, uri))
|
||||
test('POST 4', () {
|
||||
const expectedCode = r'''using System;
|
||||
using System.Net.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
string uri = "https://api.apidash.dev/io/form";
|
||||
|
||||
using (var client = new HttpClient())
|
||||
using (var request = new HttpRequestMessage(HttpMethod.Post, uri))
|
||||
{
|
||||
var payload = new Dictionary<string, string>
|
||||
var content = new MultipartFormDataContent
|
||||
{
|
||||
{ "text", "API" },
|
||||
{ "sep", "|" },
|
||||
{ "times", "3" },
|
||||
{ new StringContent("API"), "text" },
|
||||
{ new StringContent("|"), "sep" },
|
||||
{ new StringContent("3"), "times" },
|
||||
};
|
||||
var content = new FormUrlEncodedContent(payload);
|
||||
request.Content = content;
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(request);
|
||||
@ -389,7 +388,7 @@ using (var request = new HttpRequestMessage(HttpMethod.Post, uri))
|
||||
test('POST 5', () {
|
||||
const expectedCode = r'''using System;
|
||||
using System.Net.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
string uri = "https://api.apidash.dev/io/form";
|
||||
|
||||
@ -398,13 +397,12 @@ using (var request = new HttpRequestMessage(HttpMethod.Post, uri))
|
||||
{
|
||||
request.Headers.Add("User-Agent", "Test Agent");
|
||||
|
||||
var payload = new Dictionary<string, string>
|
||||
var content = new MultipartFormDataContent
|
||||
{
|
||||
{ "text", "API" },
|
||||
{ "sep", "|" },
|
||||
{ "times", "3" },
|
||||
{ new StringContent("API"), "text" },
|
||||
{ new StringContent("|"), "sep" },
|
||||
{ new StringContent("3"), "times" },
|
||||
};
|
||||
var content = new FormUrlEncodedContent(payload);
|
||||
request.Content = content;
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(request);
|
||||
@ -479,20 +477,19 @@ using (var request = new HttpRequestMessage(HttpMethod.Post, uri))
|
||||
test('POST 8', () {
|
||||
const expectedCode = r'''using System;
|
||||
using System.Net.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
string uri = "https://api.apidash.dev/io/form?size=2&len=3";
|
||||
|
||||
using (var client = new HttpClient())
|
||||
using (var request = new HttpRequestMessage(HttpMethod.Post, uri))
|
||||
{
|
||||
var payload = new Dictionary<string, string>
|
||||
var content = new MultipartFormDataContent
|
||||
{
|
||||
{ "text", "API" },
|
||||
{ "sep", "|" },
|
||||
{ "times", "3" },
|
||||
{ new StringContent("API"), "text" },
|
||||
{ new StringContent("|"), "sep" },
|
||||
{ new StringContent("3"), "times" },
|
||||
};
|
||||
var content = new FormUrlEncodedContent(payload);
|
||||
request.Content = content;
|
||||
|
||||
HttpResponseMessage response = await client.SendAsync(request);
|
||||
|
Reference in New Issue
Block a user