How can I convince Refit not to add the xml preamble?How can I build XML in C#?How can I get the application's path in a .NET console application?How to send XML Data as Request using XML Web ServiceHow can I generate random alphanumeric strings?HttpWebRequest with pages that have dynamically generated html from javascript?How to set Accept and Accept-Language header fields?Incompatible Type when using web serviceEncoding with HttpClient in .NET 4.5WebClient EncodingRead POST Request body in Web API 2
Do living authors still get paid royalties for their old work?
Why didn’t Doctor Strange stay in the original winning timeline?
Can others monetize my project with GPLv3?
Why don't sharp and flat root note chords seem to be present in much guitar music?
Why doesn't the Falcon-9 first stage use three legs to land?
Why does my air conditioner still run, even when it is cooler outside than in?
How many spells can a level 1 wizard learn?
How big would a Daddy Longlegs Spider need to be to kill an average Human?
Is this kind of description not recommended?
Repurpose telephone line to ethernet
How does the Saturn V Dynamic Test Stand work?
Multicolumn in table not centered
Stuffing in the middle
Find Two largest numbers in a list without using Array
Can my Boyfriend, who lives in the UK and has a Polish passport, visit me in the USA?
Gofer work in exchange for Letter of Recommendation
Writing/buying Seforim rather than Sefer Torah
Are there any OR challenges that are similar to kaggle's competitions?
Vacuum collapse -- why do strong metals implode but glass doesn't?
What happened after the end of the Truman Show?
Changing a TGV booking
Unsolved Problems (Not Independent of ZFC) due to Lack of Computational Power
Chess software to analyze games
How could China have extradited people for political reason under the extradition law it wanted to pass in Hong Kong?
How can I convince Refit not to add the xml preamble?
How can I build XML in C#?How can I get the application's path in a .NET console application?How to send XML Data as Request using XML Web ServiceHow can I generate random alphanumeric strings?HttpWebRequest with pages that have dynamically generated html from javascript?How to set Accept and Accept-Language header fields?Incompatible Type when using web serviceEncoding with HttpClient in .NET 4.5WebClient EncodingRead POST Request body in Web API 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am a newbie in using Refit. I am using Refit now to call a REST Api that expects xml as input. This works but it seems that Refit automatically adds the well known xml preamble to describe encoding.
I want to send the xml element without preamble (as required by the target system). How do I do this? Here is my code in the startup class:
var settings = new RefitSettings
ContentSerializer = new XmlContentSerializer()
;
services.AddRefitClient<IItemApi>(settings)
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://127.0.0.1:5000"));
Here is my data class and just used interface
public class PayLoad
public string A get; set;
public string B get; set;
public interface IItemApi
[Post("/target/id")]
Task<ApiResponse<string>> PostItemAsync(string id, [Body] PayLoad item,
CancellationToken cancellationToken = default);
Here is an example of a post call:
var result = itemApi.PostItemAsync("X",new PayLoad
A = "A",
B = "B"
);
This is the raw request:
POST http://127.0.0.1:5000/target/X HTTP/1.1
Content-Type: application/xml; charset=utf-8
Content-Length: 76
Host: 127.0.0.1:5000
<?xml version="1.0" encoding="utf-8"?><PayLoad><A>A</A><B>B</B></PayLoad>
How can I change my code in such a way this part
<?xml version="1.0" encoding="utf-8"?>
is not in the request anymore?
c# httpwebrequest refit
add a comment |
I am a newbie in using Refit. I am using Refit now to call a REST Api that expects xml as input. This works but it seems that Refit automatically adds the well known xml preamble to describe encoding.
I want to send the xml element without preamble (as required by the target system). How do I do this? Here is my code in the startup class:
var settings = new RefitSettings
ContentSerializer = new XmlContentSerializer()
;
services.AddRefitClient<IItemApi>(settings)
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://127.0.0.1:5000"));
Here is my data class and just used interface
public class PayLoad
public string A get; set;
public string B get; set;
public interface IItemApi
[Post("/target/id")]
Task<ApiResponse<string>> PostItemAsync(string id, [Body] PayLoad item,
CancellationToken cancellationToken = default);
Here is an example of a post call:
var result = itemApi.PostItemAsync("X",new PayLoad
A = "A",
B = "B"
);
This is the raw request:
POST http://127.0.0.1:5000/target/X HTTP/1.1
Content-Type: application/xml; charset=utf-8
Content-Length: 76
Host: 127.0.0.1:5000
<?xml version="1.0" encoding="utf-8"?><PayLoad><A>A</A><B>B</B></PayLoad>
How can I change my code in such a way this part
<?xml version="1.0" encoding="utf-8"?>
is not in the request anymore?
c# httpwebrequest refit
I'd hope you can't, as without that part it is not valid xml. By the way, that part is also called XML-Declaration. EDIT: I just read that only in version="1.1" it's mandatory, but even in version="1.0" it is heavily recommended
– MindSwipe
Mar 27 at 14:47
This is not how my target system expects it. Moreover, it is also not very usual for web requests. For example the PostXmlAsync of HttpClient does not do it. In addition, it is redundant. The encoding is already mentioned as Http header info (in the Content-Type).
– Daan
Mar 27 at 15:01
The encoding actually isn't necessary, even in v1.1, so you can omit that. And what kind of XML deserializer does your target system use if it isn't expecting an xml declaration?
– MindSwipe
Mar 27 at 15:03
I know only one thing of the target system (created by an external party): a request works if I just send it without the preamble.
– Daan
Mar 27 at 15:21
Ok, then what I would do now is 1. Get in contact with said external party and ask them what's up with them not accepting valid XML and then 2. Serialize the XML to a string, remove the declaration and then send it
– MindSwipe
Mar 27 at 15:23
add a comment |
I am a newbie in using Refit. I am using Refit now to call a REST Api that expects xml as input. This works but it seems that Refit automatically adds the well known xml preamble to describe encoding.
I want to send the xml element without preamble (as required by the target system). How do I do this? Here is my code in the startup class:
var settings = new RefitSettings
ContentSerializer = new XmlContentSerializer()
;
services.AddRefitClient<IItemApi>(settings)
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://127.0.0.1:5000"));
Here is my data class and just used interface
public class PayLoad
public string A get; set;
public string B get; set;
public interface IItemApi
[Post("/target/id")]
Task<ApiResponse<string>> PostItemAsync(string id, [Body] PayLoad item,
CancellationToken cancellationToken = default);
Here is an example of a post call:
var result = itemApi.PostItemAsync("X",new PayLoad
A = "A",
B = "B"
);
This is the raw request:
POST http://127.0.0.1:5000/target/X HTTP/1.1
Content-Type: application/xml; charset=utf-8
Content-Length: 76
Host: 127.0.0.1:5000
<?xml version="1.0" encoding="utf-8"?><PayLoad><A>A</A><B>B</B></PayLoad>
How can I change my code in such a way this part
<?xml version="1.0" encoding="utf-8"?>
is not in the request anymore?
c# httpwebrequest refit
I am a newbie in using Refit. I am using Refit now to call a REST Api that expects xml as input. This works but it seems that Refit automatically adds the well known xml preamble to describe encoding.
I want to send the xml element without preamble (as required by the target system). How do I do this? Here is my code in the startup class:
var settings = new RefitSettings
ContentSerializer = new XmlContentSerializer()
;
services.AddRefitClient<IItemApi>(settings)
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://127.0.0.1:5000"));
Here is my data class and just used interface
public class PayLoad
public string A get; set;
public string B get; set;
public interface IItemApi
[Post("/target/id")]
Task<ApiResponse<string>> PostItemAsync(string id, [Body] PayLoad item,
CancellationToken cancellationToken = default);
Here is an example of a post call:
var result = itemApi.PostItemAsync("X",new PayLoad
A = "A",
B = "B"
);
This is the raw request:
POST http://127.0.0.1:5000/target/X HTTP/1.1
Content-Type: application/xml; charset=utf-8
Content-Length: 76
Host: 127.0.0.1:5000
<?xml version="1.0" encoding="utf-8"?><PayLoad><A>A</A><B>B</B></PayLoad>
How can I change my code in such a way this part
<?xml version="1.0" encoding="utf-8"?>
is not in the request anymore?
c# httpwebrequest refit
c# httpwebrequest refit
edited Mar 30 at 2:25
Daan
asked Mar 27 at 14:44
DaanDaan
1,1071 gold badge13 silver badges34 bronze badges
1,1071 gold badge13 silver badges34 bronze badges
I'd hope you can't, as without that part it is not valid xml. By the way, that part is also called XML-Declaration. EDIT: I just read that only in version="1.1" it's mandatory, but even in version="1.0" it is heavily recommended
– MindSwipe
Mar 27 at 14:47
This is not how my target system expects it. Moreover, it is also not very usual for web requests. For example the PostXmlAsync of HttpClient does not do it. In addition, it is redundant. The encoding is already mentioned as Http header info (in the Content-Type).
– Daan
Mar 27 at 15:01
The encoding actually isn't necessary, even in v1.1, so you can omit that. And what kind of XML deserializer does your target system use if it isn't expecting an xml declaration?
– MindSwipe
Mar 27 at 15:03
I know only one thing of the target system (created by an external party): a request works if I just send it without the preamble.
– Daan
Mar 27 at 15:21
Ok, then what I would do now is 1. Get in contact with said external party and ask them what's up with them not accepting valid XML and then 2. Serialize the XML to a string, remove the declaration and then send it
– MindSwipe
Mar 27 at 15:23
add a comment |
I'd hope you can't, as without that part it is not valid xml. By the way, that part is also called XML-Declaration. EDIT: I just read that only in version="1.1" it's mandatory, but even in version="1.0" it is heavily recommended
– MindSwipe
Mar 27 at 14:47
This is not how my target system expects it. Moreover, it is also not very usual for web requests. For example the PostXmlAsync of HttpClient does not do it. In addition, it is redundant. The encoding is already mentioned as Http header info (in the Content-Type).
– Daan
Mar 27 at 15:01
The encoding actually isn't necessary, even in v1.1, so you can omit that. And what kind of XML deserializer does your target system use if it isn't expecting an xml declaration?
– MindSwipe
Mar 27 at 15:03
I know only one thing of the target system (created by an external party): a request works if I just send it without the preamble.
– Daan
Mar 27 at 15:21
Ok, then what I would do now is 1. Get in contact with said external party and ask them what's up with them not accepting valid XML and then 2. Serialize the XML to a string, remove the declaration and then send it
– MindSwipe
Mar 27 at 15:23
I'd hope you can't, as without that part it is not valid xml. By the way, that part is also called XML-Declaration. EDIT: I just read that only in version="1.1" it's mandatory, but even in version="1.0" it is heavily recommended
– MindSwipe
Mar 27 at 14:47
I'd hope you can't, as without that part it is not valid xml. By the way, that part is also called XML-Declaration. EDIT: I just read that only in version="1.1" it's mandatory, but even in version="1.0" it is heavily recommended
– MindSwipe
Mar 27 at 14:47
This is not how my target system expects it. Moreover, it is also not very usual for web requests. For example the PostXmlAsync of HttpClient does not do it. In addition, it is redundant. The encoding is already mentioned as Http header info (in the Content-Type).
– Daan
Mar 27 at 15:01
This is not how my target system expects it. Moreover, it is also not very usual for web requests. For example the PostXmlAsync of HttpClient does not do it. In addition, it is redundant. The encoding is already mentioned as Http header info (in the Content-Type).
– Daan
Mar 27 at 15:01
The encoding actually isn't necessary, even in v1.1, so you can omit that. And what kind of XML deserializer does your target system use if it isn't expecting an xml declaration?
– MindSwipe
Mar 27 at 15:03
The encoding actually isn't necessary, even in v1.1, so you can omit that. And what kind of XML deserializer does your target system use if it isn't expecting an xml declaration?
– MindSwipe
Mar 27 at 15:03
I know only one thing of the target system (created by an external party): a request works if I just send it without the preamble.
– Daan
Mar 27 at 15:21
I know only one thing of the target system (created by an external party): a request works if I just send it without the preamble.
– Daan
Mar 27 at 15:21
Ok, then what I would do now is 1. Get in contact with said external party and ask them what's up with them not accepting valid XML and then 2. Serialize the XML to a string, remove the declaration and then send it
– MindSwipe
Mar 27 at 15:23
Ok, then what I would do now is 1. Get in contact with said external party and ask them what's up with them not accepting valid XML and then 2. Serialize the XML to a string, remove the declaration and then send it
– MindSwipe
Mar 27 at 15:23
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380035%2fhow-can-i-convince-refit-not-to-add-the-xml-preamble%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380035%2fhow-can-i-convince-refit-not-to-add-the-xml-preamble%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'd hope you can't, as without that part it is not valid xml. By the way, that part is also called XML-Declaration. EDIT: I just read that only in version="1.1" it's mandatory, but even in version="1.0" it is heavily recommended
– MindSwipe
Mar 27 at 14:47
This is not how my target system expects it. Moreover, it is also not very usual for web requests. For example the PostXmlAsync of HttpClient does not do it. In addition, it is redundant. The encoding is already mentioned as Http header info (in the Content-Type).
– Daan
Mar 27 at 15:01
The encoding actually isn't necessary, even in v1.1, so you can omit that. And what kind of XML deserializer does your target system use if it isn't expecting an xml declaration?
– MindSwipe
Mar 27 at 15:03
I know only one thing of the target system (created by an external party): a request works if I just send it without the preamble.
– Daan
Mar 27 at 15:21
Ok, then what I would do now is 1. Get in contact with said external party and ask them what's up with them not accepting valid XML and then 2. Serialize the XML to a string, remove the declaration and then send it
– MindSwipe
Mar 27 at 15:23