The remote server returned an error: (401) Unauthorized.

191 views
Skip to first unread message

menos...@googlemail.com

unread,
Oct 9, 2015, 9:57:26 AM10/9/15
to Fujitsu RunMyProcess Developer Community
Hey guys, im trying to gain access through visual studio, however im getting the following error saying that :

The remote server returned an error: (401) Unauthorized.

The code below is what i have, not sure where am going wrong even though when i run it in SoapUI, it runs perfectly fine, can someone help me out? Thanks in advance.


tbJson.Text = jb.ToString();

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://live.runmyprocess.com/live/115281425483556936/process/148564?P_mode=TEST");

String encoded = System.Convert.ToBase64String( Encoding.UTF8.GetBytes("********.fujitsu.com:password"));

string json = System.Convert.ToBase64String( Encoding.UTF8.GetBytes(jb.ToString()));

var content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\" xml:base=\"https://live.runmyprocess.com/\"><title>Title</title><entry><title>Title</title><content type=\"text/base64\">" + json + " </content></entry></feed>";

tbContent.Text = content;

var postData = content;

var data = Encoding.ASCII.GetBytes(postData);

request.Method = "POST";
request.ContentType = "application/xml";
request.ContentLength = data.Length;
request.Headers[HttpRequestHeader.Authorization] = "Basic " + encoded;
//request.Headers.Add("Authorization", "Basic " + encoded);

using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}

try
{
var response = (HttpWebResponse)request.GetResponse();

var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

MessageBox.Show("Incident reported");

// Application.Exit();

}

Bidisha Das

unread,
Oct 10, 2015, 8:35:58 AM10/10/15
to suppor...@runmyprocess.com
Hi,
Please try with the below code:

tbJson.Text = jb.ToString();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://live.runmyprocess.com/live/115281425483556936/process/148564?P_mode=TEST");/* Made changes over here*/

            String encoded = System.Convert.ToBase64String( Encoding.UTF8.GetBytes("********.fujitsu.com:password"));

            string json = System.Convert.ToBase64String( Encoding.UTF8.GetBytes(jb.ToString()));

 var content = "<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xml:base='https://live.runmyprocess.com/ <http://www.w3.org/2005/Atom%27%20xml:base=%27https://live.runmyprocess.com/> '><title>Subprocess_validation</title><link rel='self' href='live/661134565/process/116630' /><id>116630</id><rights>(c) RunMyProcess 2015</rights><updated>2015-10-10T11:34:37Z</updated><entry><title>Parameters</title><category term='initial' /><id>116630</id><published>2015-10-10T11:34:37Z</published><content type='xml'>{}</content></entry></feed>"

            tbContent.Text = content; 
var postData = content;

            var data = Encoding.ASCII.GetBytes(postData);

            request.Method = "POST";
            request.ContentType = "application/xml";
            request.ContentLength = data.Length;
            request.Headers[HttpRequestHeader.Authorization] = "Basic " + encoded;
            //request.Headers.Add("Authorization", "Basic " + encoded);

            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            try
            {
                var response = (HttpWebResponse)request.GetResponse();

var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            MessageBox.Show("Incident reported");

            // Application.Exit();

        } 



Thanks & Regards
Bidisha

menos...@googlemail.com

unread,
Oct 20, 2015, 4:24:14 AM10/20/15
to Fujitsu RunMyProcess Developer Community, menos...@googlemail.com
Hi i tried your suggestion but now it comes up with the following error:


System.Net Error: 0 : [9272] Exception in HttpWebRequest#44483489::GetResponse - The remote server returned an error: (400) Bad Request..
The remote server returned an error: (400) Bad Request.

where is it going wrong?


BELOW IS THE CODE I HAVE:

tbJson.Text = jb.ToString();

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://live.runmyprocess.com/live/115281425483556936/process/148564?P_mode=TEST");/* Made changes over here*/

String encoded = System.Convert.ToBase64String( Encoding.UTF8.GetBytes("email...@ts.fujitsu.com:*****"));

string json = System.Convert.ToBase64String( Encoding.UTF8.GetBytes(jb.ToString()));

var content = "<feed xmlns=\"http://www.w3.org/2005/Atom\" xml:base=\"https://live.runmyprocess.com/\"><title>KLM - Computer Info</title><link rel=\"self\" href=\"live/115281425483556936/process/148564\" /><id>148564</id><rights>(c) RunMyProcess 2015</rights><updated>2015-10-12T07:55:02Z</updated><entry><title>Parameters</title><category term=\"initial\" /><id>148564</id> <published>2015-10-12T07:55:02Z</published><content type=\"xml\">" + json + "</content></entry></feed>";

// "<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xml:base='https://live.runmyprocess.com/ <http://www.w3.org/2005/Atom%27%20xml:base=%27https://live.runmyprocess.com/> '><title>Subprocess_validation</title><link rel='self' href='live/661134565/process/116630' /><id>116630</id><rights>(c) RunMyProcess 2015</rights><updated>2015-10-10T11:34:37Z</updated><entry><title>Parameters</title><category term='initial' /><id>116630</id><published>2015-10-10T11:34:37Z</published><content type='xml'>"+ json + "</content></entry></feed>";

tbContent.Text = content;
var postData = content;

var data = Encoding.ASCII.GetBytes(postData);

request.Method = "POST";
request.ContentType = "application/xml";
request.ContentLength = data.Length;
request.Headers[HttpRequestHeader.Authorization] = "Basic " + encoded;
//request.Headers.Add("Authorization", "Basic " + encoded);

using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}

try
{
var response = (HttpWebResponse)request.GetResponse();

var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

MessageBox.Show("Incident reported");

// Application.Exit();

}

Thanks in advance

menos...@googlemail.com

unread,
Oct 20, 2015, 4:48:05 AM10/20/15
to Fujitsu RunMyProcess Developer Community, menos...@googlemail.com
and to add to your previous reply, when you said you made changes to the url below, there wasnt any changes made to it.

Bidisha Das

unread,
Oct 24, 2015, 4:41:45 PM10/24/15
to suppor...@runmyprocess.com
Hi,
The below code is working fine for me.Would you please make the required changes and run it once to check from your side?

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Net;

using System.IO;

 

namespace Bidisha_Trial

{

    class Program

   {

        static void Main(string[] args)

        {

            //tbJson.Text = jb.ToString();

            var jb = "jsontext";

 

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://live.runmyprocess.com/live/661134565/process/116630?P_mode=TEST");

 

            String encoded = System.Convert.ToBase64String( Encoding.UTF8.GetBytes("bidis...@in.fujitsu.com:bidisha@2014"));

 

            string json = System.Convert.ToBase64String( Encoding.UTF8.GetBytes(jb.ToString()));

 

            //var content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\<http://www.w3.org/2005/Atom/> " xml:base=\"https://live.runmyprocess.com/\ <https://live.runmyprocess.com//> "><title>Title</title><entry><title>Title</title><content type=\"text/base64\"></content></entry></feed>";

 

            var content = "<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xml:base='https://live.runmyprocess.com/'><title>Subprocess_validation</title><link rel='self' href='live/661134565/process/116630' /><id>116630</id><rights>(c) RunMyProcess 2015</rights><updated>2015-10-10T11:34:37Z</updated><entry><title>Parameters</title><category term='initial' /><id>116630</id><published>2015-10-10T11:34:37Z</published><content type='xml'>{'test':'abc'}</content></entry></feed>";

 

            //tbContent.Text = content;

            var postData = content;

 

            var data = Encoding.ASCII.GetBytes(postData);

 

            //var data = "";

 

            request.Method = "POST";

            request.ContentType = "application/xml";

            //request.ContentLength = data.Length;

            request.Headers[HttpRequestHeader.Authorization] = "Basic " + encoded;

            //request.Headers.Add("Authorization", "Basic " + encoded);

 

            using (var stream = request.GetRequestStream())

            {

                stream.Write(data, 0, data.Length);

            }

 

            try

            {

                var response = (HttpWebResponse)request.GetResponse();

 

            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            }

            catch(Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

 

            //MessageBox.Show("Incident reported");

 

            // Application.Exit();

        }

    }

}




Thanks & Regards
Bidisha
Reply all
Reply to author
Forward
0 new messages