Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

HttpWebRequest-The remote server returned an error: (400) Bad Request

ProgrammerProgrammer Member ✭✭

i am working on push notification with onesignal .i am getting some error while requesting to web server,like HttpWebRequest-The remote server returned an error: (400) Bad Request and System.Net.WebException: Value cannot be null. Parameter name: src. any body know about this ,please help me... here is my code

using System.IO;
using System.Net;
using System.Text;

var request = WebRequest.Create("") as HttpWebRequest;

request.KeepAlive = true;
request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";

request.Headers.Add("authorization", "Basic My_API_Key");

byte[] byteArray = Encoding.UTF8.GetBytes("{"
                                        + "\"app_id\": \"My_app_id\","
                                        + "\"contents\": {\"en\": \"English Message\"},"
                                        + "\"filters\": [{\"field\": \"tag\", \"key\": \"level\", \"relation\": \">\", \"value\": \"10\"}]}");

string responseContent = null;

try {
    using (var writer = request.GetRequestStream()) {
        writer.Write(byteArray, 0, byteArray.Length);

    using (var response = request.GetResponse() as HttpWebResponse) {
        using (var reader = new StreamReader(response.GetResponseStream())) {
            responseContent = reader.ReadToEnd();
catch (WebException ex) {
    System.Diagnostics.Debug.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd());

Sign In or Register to comment.