How to select data from Basic authorization with post data?
How to select some data from this service (http://192.168.1.18/service/test) which this value > {"number":"11224455", "name":"person1"}
. Basic authorization: {username: "admin",password: "pass123"}
This is the sample of making a POST request in C# with Basic Authentication: It goes error with: The remote server returned an error: (401) Unauthorized. where put I username and password?
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestPostExample
{
public static void Main ()
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://192.168.1.18/service/test");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();
}
}
}
c# asp.net http-post
add a comment |
How to select some data from this service (http://192.168.1.18/service/test) which this value > {"number":"11224455", "name":"person1"}
. Basic authorization: {username: "admin",password: "pass123"}
This is the sample of making a POST request in C# with Basic Authentication: It goes error with: The remote server returned an error: (401) Unauthorized. where put I username and password?
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestPostExample
{
public static void Main ()
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://192.168.1.18/service/test");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();
}
}
}
c# asp.net http-post
What problem are you experiencing?
– Crowcoder
Nov 20 '18 at 1:27
How do I select data with value {"number":"11224455", "name":"person1"}?
– Solution
Nov 20 '18 at 1:32
And should add this line to pass basic authorization:request.Credentials = new NetworkCredential("admin1", "pass123");
– Solution
Nov 21 '18 at 0:46
add a comment |
How to select some data from this service (http://192.168.1.18/service/test) which this value > {"number":"11224455", "name":"person1"}
. Basic authorization: {username: "admin",password: "pass123"}
This is the sample of making a POST request in C# with Basic Authentication: It goes error with: The remote server returned an error: (401) Unauthorized. where put I username and password?
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestPostExample
{
public static void Main ()
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://192.168.1.18/service/test");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();
}
}
}
c# asp.net http-post
How to select some data from this service (http://192.168.1.18/service/test) which this value > {"number":"11224455", "name":"person1"}
. Basic authorization: {username: "admin",password: "pass123"}
This is the sample of making a POST request in C# with Basic Authentication: It goes error with: The remote server returned an error: (401) Unauthorized. where put I username and password?
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestPostExample
{
public static void Main ()
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://192.168.1.18/service/test");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();
}
}
}
c# asp.net http-post
c# asp.net http-post
edited Nov 22 '18 at 2:45
Solution
asked Nov 20 '18 at 1:09


SolutionSolution
72118
72118
What problem are you experiencing?
– Crowcoder
Nov 20 '18 at 1:27
How do I select data with value {"number":"11224455", "name":"person1"}?
– Solution
Nov 20 '18 at 1:32
And should add this line to pass basic authorization:request.Credentials = new NetworkCredential("admin1", "pass123");
– Solution
Nov 21 '18 at 0:46
add a comment |
What problem are you experiencing?
– Crowcoder
Nov 20 '18 at 1:27
How do I select data with value {"number":"11224455", "name":"person1"}?
– Solution
Nov 20 '18 at 1:32
And should add this line to pass basic authorization:request.Credentials = new NetworkCredential("admin1", "pass123");
– Solution
Nov 21 '18 at 0:46
What problem are you experiencing?
– Crowcoder
Nov 20 '18 at 1:27
What problem are you experiencing?
– Crowcoder
Nov 20 '18 at 1:27
How do I select data with value {"number":"11224455", "name":"person1"}?
– Solution
Nov 20 '18 at 1:32
How do I select data with value {"number":"11224455", "name":"person1"}?
– Solution
Nov 20 '18 at 1:32
And should add this line to pass basic authorization:
request.Credentials = new NetworkCredential("admin1", "pass123");
– Solution
Nov 21 '18 at 0:46
And should add this line to pass basic authorization:
request.Credentials = new NetworkCredential("admin1", "pass123");
– Solution
Nov 21 '18 at 0:46
add a comment |
1 Answer
1
active
oldest
votes
Since your comment seems to suggest it's a single resulting JSON object:
Declare your class with the properties you need to capture:
public class Person
{
public int number { get; set; }
public string name { get; set; }
}
Then you can capture it via Newtonsoft.Json with something like this:
Person person = Newtonsoft.Json.JsonConvert.DeserializeObject<Person>(responseFromServer);
Console.WriteLine("id: {0}, name: {1}", person.name, person.number);
where can I put Basic authorization username and password?
– Solution
Nov 21 '18 at 0:26
Also 'Newtonsoft' doesn't work it
– Solution
Nov 21 '18 at 0:48
You'll need to import the reference for Newtonsoft JSON for it to work.
– Nathan Champion
Nov 21 '18 at 1:55
It goes error with The remote server returned an error: (401) Unauthorized. How to put username and password it?
– Solution
Nov 21 '18 at 4:00
That all depends on how the post username/pass are handled. What are you trying to accomplish? Also, what do you mean by "basic auth" a Username/pass popup when you head to that page?
– Nathan Champion
Nov 22 '18 at 5:08
|
show 1 more comment
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%2f53384830%2fhow-to-select-data-from-basic-authorization-with-post-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since your comment seems to suggest it's a single resulting JSON object:
Declare your class with the properties you need to capture:
public class Person
{
public int number { get; set; }
public string name { get; set; }
}
Then you can capture it via Newtonsoft.Json with something like this:
Person person = Newtonsoft.Json.JsonConvert.DeserializeObject<Person>(responseFromServer);
Console.WriteLine("id: {0}, name: {1}", person.name, person.number);
where can I put Basic authorization username and password?
– Solution
Nov 21 '18 at 0:26
Also 'Newtonsoft' doesn't work it
– Solution
Nov 21 '18 at 0:48
You'll need to import the reference for Newtonsoft JSON for it to work.
– Nathan Champion
Nov 21 '18 at 1:55
It goes error with The remote server returned an error: (401) Unauthorized. How to put username and password it?
– Solution
Nov 21 '18 at 4:00
That all depends on how the post username/pass are handled. What are you trying to accomplish? Also, what do you mean by "basic auth" a Username/pass popup when you head to that page?
– Nathan Champion
Nov 22 '18 at 5:08
|
show 1 more comment
Since your comment seems to suggest it's a single resulting JSON object:
Declare your class with the properties you need to capture:
public class Person
{
public int number { get; set; }
public string name { get; set; }
}
Then you can capture it via Newtonsoft.Json with something like this:
Person person = Newtonsoft.Json.JsonConvert.DeserializeObject<Person>(responseFromServer);
Console.WriteLine("id: {0}, name: {1}", person.name, person.number);
where can I put Basic authorization username and password?
– Solution
Nov 21 '18 at 0:26
Also 'Newtonsoft' doesn't work it
– Solution
Nov 21 '18 at 0:48
You'll need to import the reference for Newtonsoft JSON for it to work.
– Nathan Champion
Nov 21 '18 at 1:55
It goes error with The remote server returned an error: (401) Unauthorized. How to put username and password it?
– Solution
Nov 21 '18 at 4:00
That all depends on how the post username/pass are handled. What are you trying to accomplish? Also, what do you mean by "basic auth" a Username/pass popup when you head to that page?
– Nathan Champion
Nov 22 '18 at 5:08
|
show 1 more comment
Since your comment seems to suggest it's a single resulting JSON object:
Declare your class with the properties you need to capture:
public class Person
{
public int number { get; set; }
public string name { get; set; }
}
Then you can capture it via Newtonsoft.Json with something like this:
Person person = Newtonsoft.Json.JsonConvert.DeserializeObject<Person>(responseFromServer);
Console.WriteLine("id: {0}, name: {1}", person.name, person.number);
Since your comment seems to suggest it's a single resulting JSON object:
Declare your class with the properties you need to capture:
public class Person
{
public int number { get; set; }
public string name { get; set; }
}
Then you can capture it via Newtonsoft.Json with something like this:
Person person = Newtonsoft.Json.JsonConvert.DeserializeObject<Person>(responseFromServer);
Console.WriteLine("id: {0}, name: {1}", person.name, person.number);
answered Nov 20 '18 at 2:13


Nathan ChampionNathan Champion
559111
559111
where can I put Basic authorization username and password?
– Solution
Nov 21 '18 at 0:26
Also 'Newtonsoft' doesn't work it
– Solution
Nov 21 '18 at 0:48
You'll need to import the reference for Newtonsoft JSON for it to work.
– Nathan Champion
Nov 21 '18 at 1:55
It goes error with The remote server returned an error: (401) Unauthorized. How to put username and password it?
– Solution
Nov 21 '18 at 4:00
That all depends on how the post username/pass are handled. What are you trying to accomplish? Also, what do you mean by "basic auth" a Username/pass popup when you head to that page?
– Nathan Champion
Nov 22 '18 at 5:08
|
show 1 more comment
where can I put Basic authorization username and password?
– Solution
Nov 21 '18 at 0:26
Also 'Newtonsoft' doesn't work it
– Solution
Nov 21 '18 at 0:48
You'll need to import the reference for Newtonsoft JSON for it to work.
– Nathan Champion
Nov 21 '18 at 1:55
It goes error with The remote server returned an error: (401) Unauthorized. How to put username and password it?
– Solution
Nov 21 '18 at 4:00
That all depends on how the post username/pass are handled. What are you trying to accomplish? Also, what do you mean by "basic auth" a Username/pass popup when you head to that page?
– Nathan Champion
Nov 22 '18 at 5:08
where can I put Basic authorization username and password?
– Solution
Nov 21 '18 at 0:26
where can I put Basic authorization username and password?
– Solution
Nov 21 '18 at 0:26
Also 'Newtonsoft' doesn't work it
– Solution
Nov 21 '18 at 0:48
Also 'Newtonsoft' doesn't work it
– Solution
Nov 21 '18 at 0:48
You'll need to import the reference for Newtonsoft JSON for it to work.
– Nathan Champion
Nov 21 '18 at 1:55
You'll need to import the reference for Newtonsoft JSON for it to work.
– Nathan Champion
Nov 21 '18 at 1:55
It goes error with The remote server returned an error: (401) Unauthorized. How to put username and password it?
– Solution
Nov 21 '18 at 4:00
It goes error with The remote server returned an error: (401) Unauthorized. How to put username and password it?
– Solution
Nov 21 '18 at 4:00
That all depends on how the post username/pass are handled. What are you trying to accomplish? Also, what do you mean by "basic auth" a Username/pass popup when you head to that page?
– Nathan Champion
Nov 22 '18 at 5:08
That all depends on how the post username/pass are handled. What are you trying to accomplish? Also, what do you mean by "basic auth" a Username/pass popup when you head to that page?
– Nathan Champion
Nov 22 '18 at 5:08
|
show 1 more comment
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%2f53384830%2fhow-to-select-data-from-basic-authorization-with-post-data%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
What problem are you experiencing?
– Crowcoder
Nov 20 '18 at 1:27
How do I select data with value {"number":"11224455", "name":"person1"}?
– Solution
Nov 20 '18 at 1:32
And should add this line to pass basic authorization:
request.Credentials = new NetworkCredential("admin1", "pass123");
– Solution
Nov 21 '18 at 0:46