Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:18:06+00:00 2026-06-14T09:18:06+00:00

I am trying to post this JSON data string to my php site: {

  • 0

I am trying to post this JSON data string to my php site:

{
    "tag":"login"
    "email":"email@email.com"
    "password":"P@ssw0rd"
}

this is my C# code that I have:

        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri("http://localhost/login/");
        string link = "http://localhost/login/";

        UserCredentials cred = new UserCredentials(email.Text, pass.Password.ToString());
        var data = new Dictionary<string, List<UserCredentials>>();
        string json = JsonConvert.SerializeObject(data, Formatting.Indented);


        HttpResponseMessage re = await client.PostAsync(link, new StringContent(json));

User credentials class:

public class UserCredentials
{
    public UserCredentials(string user, string pass)
    {
        User = user;
        Pass = pass;
        Tag = "login";
    }

    internal string User;
    internal string Pass;
    internal string Tag;
}

in my php script :

<?php

if (isset($_POST['tag']) && $_POST['tag'] != '') {
  echo "got tags";
else 
  echo "didn't get anything";
?>

does anyone know how I am supposed to send the tags over the postasync method? I am getting ‘didn’t get anything’ .. please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:18:07+00:00Added an answer on June 14, 2026 at 9:18 am

    First, fix your UserCredentials class. Make your memebers public, not internal.

    public class UserCredentials
    {
        public UserCredentials(string user, string pass)
        {
            User = user;
            Pass = pass;
            Tag = "login";
        }
    
        public string User;
        public string Pass;
        public string Tag;
    }
    

    Second, serialize only your credentials.

    UserCredentials cred = new UserCredentials(email.Text, pass.Password.ToString());
    string json = JsonConvert.SerializeObject(cred, Formatting.Indented);
    System.Diagnostics.Debug.WriteLine(json);
    

    You will see in the Output window something like this:

    {
      "User": "me@hotmail.com",
      "Pass": "ILoveToEatGrapes",
      "Tag": "login"
    }
    

    Third, replace StringContent with FormUrlEncodedContent

    If you are using PHP $_POST, then you must send something like key1=value1&key2=value2 in your HTTP request. This is called x-www-form-urlencoded and HttpClient contains the right class for this: FormUrlEncodedContent.

    FormUrlEncodedContent receives a dictionary of key/value pairs.

    // Create the list of keys and values.
    var data = new Dictionary<string, string>();
    data["tag"] = json;
    
    // Send my keys and values.
    HttpClient client = new HttpClient();
    string link = "http://localhost/login/";
    HttpResponseMessage re = await client.PostAsync(link, new FormUrlEncodedContent(data));
    

    This will be sent through the connection:

    POST /login/ HTTP/1.1
    Content-Type: application/x-www-form-urlencoded
    Host: localhost
    Content-Length: 142
    Expect: 100-continue
    Connection: Keep-Alive
    
    tag=%7B%0D%0A++%22User%22%3A+%22me%40hotmail.com%22%2C%0D%0A++%22Pass%22%3A+%22I
    LoveToEatGrapes%22%2C%0D%0A++%22Tag%22%3A+%22login%22%0D%0A%7D
    

    Fourth, use your data in PHP

    As you see above, data is encoded with a lot of percent signs. PHP automatically decodes the data for you, so you do not need to worry about that.

    To convert the credentials from json to an array, you may use json_decode

    $cred = json_decode($_POST['tag']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this bit of javascript: var jsonString = some string of json; $.post('proxy.php',
I've been trying to send a JSON string to PHP server like this: $.ajax({
I'm trying to POSTing some data (a JSON string) from a php script to
$.post('testeUpdate.php', 'autocomplete', function(dadosResposta) { $('#ns-nome').val(dadosResposta.nsName); $('#ns-endereco').val(dadosResposta.nsAddress); }, json); I'm trying to understand this. So,
Im very new in C++ I have found this post http://msdn.microsoft.com/en-us/magazine/cc163486.aspx and trying to
I'm trying to make this: 174,myfilename.jpg Into this on the php post process page:
I found this example PHP source code at HTTP POST from PHP, without cURL
I am having issues with storing JSON data to sqlite. This is the code
Im trying to encode some html within json from PHP. The function requests data
I am trying this code: <?php $form = $_POST['myformdata']; class validacoes { function validate_year($form)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.