GithubHelp home page GithubHelp logo

flurl.http.xml's Introduction

Icon

Flurl.Http.Xml

Build status license NuGet downloads

XML extension to the excellent Flurl library

Features:

  • Get, post and receive XML models
  • Receive XDocument
  • Receive XElements with XPath

Usage:

  • Get an XDocument:
    var result = await "https://query.yahooapis.com/v1/public/yql"
        .SetQueryParam("q", "select wind from weather.forecast where woeid=2460286")
        .SetQueryParam("format", "xml")
        .GetXDocumentAsync();

    string chill = result
        ?.Element("query")
        ?.Element("results")
        ?.Element("channel")
        ?.Element(XNamespace.Get("http://xml.weather.yahoo.com/ns/rss/1.0") + "wind")
        ?.Attribute("chill")
        ?.Value;
  • Post and receive a model:
    var result = await "http://my_xml_endpoint"
        .PostXmlAsync(new TestModel { Number = 3, Text = "Test" })
        .ReceiveXml<TestModel>();

    Assert.AreEqual(3, result.Number);
    Assert.AreEqual("Test", result.Text);
  • Put a model and receive an XDocument:
    var result = await "http://my_xml_endpoint"
        .PutXmlAsync(new TestModel {Number = 3, Text = "Test"})
        .ReceiveXDocument();

    Assert.AreEqual("3", result?.Element("TestModel")?.Element("Number")?.Value);
    Assert.AreEqual("Test", result?.Element("TestModel")?.Element("Text")?.Value);

Thanks

flurl.http.xml's People

Contributors

kroniak avatar lvermeulen avatar tmenier avatar yetiish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flurl.http.xml's Issues

Flurl 3.0.0 is out

Hi Luk,

Flurl and Flurl.Http 3.0.0 have just been released.
Could you please publish a 2.0.0 of Flurl.Http.Xml ?

Thank you !
tranb3r

NET Core support

Please add NET Core (NET Standard 1.4 - 1.6) support to the package.

Flurl.Http 1.0.0 with net core 1.0.0 will be avaliable soon.

What am I missing in FLURL?

This works:
//This text box is eating the XML tags for some reason.
string xml = "123";
string up = "user" + ":" + "pass";

var client = new HttpClient();
var byteArray = Encoding.ASCII.GetBytes(up); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

var content = new StringContent(xml, Encoding.UTF8, "application/xml");
var response = client.PutAsync("https://url.org:8443/id/4", content).Result;

I get a 400 using this in flurl xml:

String ss = " https://url.org:8443/id/4"
//This text box is eating the XML tags for some reason.
string xml = "123";

await ss.WithBasicAuth("user", "pass").PutXmlAsync(xml);

What am I missing?

HTTP Headers: Accept != Content-Type

When the Accept header is not the same as the Content-Type header, we get a crash in GetMediaType -> FlurlRequestExtensions.cs

var content = new CapturedXmlContent(request.Settings.XmlSerializer().Serialize(data), request.GetMediaType());

The problem is when you are creating the request the Mime Type of the content is taken from the Accept header definition not from Content-Type

var acceptHeaders = request.Headers .Where(x => x.Key == "Accept") .ToList();

On top of this if you have any defined Accept header that is not for XML you are going to crash in
return mediaTypes.First(x => x.IndexOf("xml", StringComparison.OrdinalIgnoreCase) >= 0) ?? mediaTypes.First();

This needs to be changed to
return mediaTypes.FirstOrDefault(x => x.IndexOf("xml", StringComparison.OrdinalIgnoreCase) >= 0) ?? mediaTypes.First();

Is there a way to send an XML string instead of a model?

Essentially, I'm trying to convert this:

            var req = (HttpWebRequest)WebRequest.Create("http://blablabla.com");

            req.Credentials = CredentialCache.DefaultNetworkCredentials;
            req.Method = "POST";
            req.ContentType = "application/xml";

            UTF8Encoding utf8Enc = new UTF8Encoding();
            byte[] postBytes = utf8Enc.GetBytes(msg);

            req.ContentLength = postBytes.Length;

            using (Stream postStream = req.GetRequestStream())
                postStream.Write(postBytes, 0, postBytes.Length);

            var resp = (HttpWebResponse)req.GetResponse();

xml extensions for IFlurlResponse

Hi,
I see that a PR with xml extensions for IFlurlResponse (new type introduced in Flurl 3.0.0-pre) was merged into the dev branch a few months ago.
Is there a plan to release a nuget package soon ?
Thanks

[Request] Configurable XmlSerializer

Hello, are there any plans to make the XmlSerializer configurable?

I am using flurl in integration tests, and currently I have to use my own extensions to make the XML de-serialization error sensitive:

public static XmlSerializer NewXmlSerializerWithErrorHandling<T>()
{
    var serializer = new XmlSerializer(typeof(T));
    serializer.UnknownAttribute += Serializer_UnknownAttribute;
    serializer.UnknownElement += Serializer_UnknownElement;
    serializer.UnknownNode += Serializer_UnknownNode;
    serializer.UnreferencedObject += Serializer_UnreferencedObject;
    return serializer;
}

On the other hand json de-serialization is configurable (even globally):

FlurlHttp.Configure(settings =>
{
    settings.BeforeCall = BeforeFlurlCall;
    settings.AfterCall = AfterFlurlCall;
    settings.OnError = OnFlurlError;
    settings.JsonSerializer = new NewtonsoftJsonSerializer(new JsonSerializerSettings
    {
        MissingMemberHandling = MissingMemberHandling.Error
    });
    //settings.XmlSerializer() = ...;
});

text/xml Content Type

Is there a way to specify a Content-Type of text/xml when using this extension library? Out of the box it looks like all requests are tagged with an application/xml Content-Type.

What about PUT?

Hello,

I have a question regarding put request. i can not find a method for it.
Do i miss something?

Thanks in advance

>net core 2.1 & flurl 2.4

Hi,

Can you rebuild your library with the current release of .net core and flurl, as I'm seeing multiple errors when I try to Get xml data.
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.