473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Issue in passing username and password in HTTP Header

Hi All,

I am facing a problem in posting Web request with username and password
credentials.
I am working on migrating Java client application to .Net which will send
request to Java servlet.

Java Client application code:
HttpClient httpclient;
httpclient = new HttpClient();
UsernamePasswordCredentials usernamepasswordcredentials = new
UsernamePasswordCredentials(s, s1);
httpclient.getState().setAuthenticationPreemptive( true);
httpclient.getState().setCredentials(null, null,
usernamepasswordcredentials);
Object obj = null;


I want info on .Net equivalent to Java's UsernamePasswordCredentials class .

This UsernamePasswordCredentials is different from .net's NetworkCredential.
I tried below code itz not working.

Please guide me on this issue.

Thanks
Santhosh



public static string HttpWebServiceRequest(string url, string userName,
string password, string xmlContent, string domain, int timeoutMS, int reqtype)
{
try
{
System.Net.ServicePointManager.CertificatePolicy = new
TrustAllCertificatePolicy();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Timeout = timeoutMS;
request.ContentType = "text/xml";
request.KeepAlive = true;
request.ContentLength = xmlContent.Length;
request.ProtocolVersion = HttpVersion.Version10;


if((userName != "") && (password != ""))
// I need to use some different class here.
request.Credentials = new NetworkCredential(userName, password, domain);
using (StreamWriter sw = new StreamWriter(request.GetRequestStream()))
{
sw.Write(xmlContent);
}

using (StreamReader sr = new
StreamReader(request.GetResponse().GetResponseStre am()))
{
return sr.ReadToEnd();
}

}
catch (Exception e)
{
throw;
}
}
Jan 10 '07 #1
0 2973

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
7
by: Kun | last post by:
I have a python-cgi form whose sole purpose is to email. It has the fields 'to', 'from', 'subject', 'body', etc. and if the user fills them out and clicks submit, it will invoke another file...
5
by: libra786 | last post by:
I have created a blog and have added a login box which prompts the user for login and id before posting- The username and password have been stored in the database, however when i enter the username...
22
by: K. A. | last post by:
I have two servers at work, 'A' for testing and development, and server 'B' for production. On server A, I wrote a PHP test code to login users then direct them to a personalized page. This is...
20
by: cmbcorp | last post by:
Hi, I have been playing around with a simple php login script and im getting an error message when i attempt to log in with the username and password i set in the sql table. The error message is...
30
by: nathanwb | last post by:
I am in the learning phase of PHP/Mysql thus my question :) I have a login.php page that passes the following values.. $myusername $mypassword. on submit it sends that data to a checklogin.php...
0
by: tkarthi06 | last post by:
Hi, Can any one please tell how to pass Web Services Credentials(Web Services Username and Password) using WCF. Inorder to Communicate with Web Services i have to provide username and...
3
ddtpmyra
by: ddtpmyra | last post by:
I have log-in form before showing all the data. I got this script in one of the internet site. The problem Im having now is capturing the username and pass it to my query line. But the password has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.