0

Here is the JavaScript

function ChangeVol(id)
{
    document.form.selectFS_devId.value = id;
    document.form.selectFS_currentNameSpace.value = "";
    document.form.submit();
}
function ChangeEvsVol(id, vNodeId)
{
    document.form.selectFS_evsId.value = vNodeId;
    document.form.selectFS_currentNameSpace.value = "";
    ChangeVol(id);
}

document.form.selectFS_devId.value = "all"  
document.form.selectFS_evsId.value = "2"

Here is the current C# code I'm using

Uri url = new Uri("https://mgr/app");
HttpWebRequest request = null;

ServicePointManager.ServerCertificateValidationCallback =
   ((sender, certificate, chain, sslPolicyErrors) => true);
CookieContainer cookieJar = new CookieContainer();

request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = cookieJar;
request.Method = "GET";
HttpStatusCode responseStatus;

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
     responseStatus = response.StatusCode;
     url = request.Address;
}

if (responseStatus == HttpStatusCode.OK)
{
      UriBuilder urlBuilder = new UriBuilder(url);
      urlBuilder.Path = 
          urlBuilder.Path.Remove(urlBuilder.Path.LastIndexOf('/')) + 
          "/j_security_check";

      request = (HttpWebRequest)WebRequest.Create(urlBuilder.ToString());
      request.Referer = url.ToString();
      request.CookieContainer = cookieJar;
      request.Method = "POST";
      request.ContentType = "application/x-www-form-urlencoded";

      using (Stream requestStream = request.GetRequestStream())
      using (StreamWriter requestWriter = new StreamWriter(requestStream, Encoding.ASCII))
      {
           string postData = "j_username=user&j_password=user&submit=Send";
           requestWriter.Write(postData);
      }

      string responseContent = null;
      string myTargetString = "https://mgr/app/action/storage.VivolAction/eventsubmit_dopreparevivollist/ignored/f5/true";
      using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
      using (Stream responseStream = response.GetResponseStream())
      using (StreamReader responseReader = new StreamReader(responseStream))
      {
         responseContent = responseReader.ReadToEnd();
      }
      Console.WriteLine(responseContent);
      request = (HttpWebRequest)WebRequest.Create(myTargetString);
      request.Method = "GET";
      request.CookieContainer = cookieJar;
      using (HttpWebResponse responsedownload = (HttpWebResponse)request.GetResponse())
      using (Stream responseStream = responsedownload.GetResponseStream())
      using (StreamReader responseReader = new StreamReader(responseStream))
      {
            responseContent = responseReader.ReadToEnd();
      }
      Console.WriteLine(responseContent);

the problem is the string myTargetString doesn't load the javascript params, if i could duplicate those params in the URL would be awesome, if not, what would I need to do to submit those in a post request like I do above in the StreamWriter?

using (StreamWriter requestWriter = new StreamWriter(requestStream, Encoding.ASCII))
            {
                string postData = "j_username=user&j_password=user&submit=Send";
                requestWriter.Write(postData);
            }

What I mean by in the url is perhaps something like:

https://mgr/app/action/storage.VivolAction/eventsubmit_dopreparevivollist/ignored?&evsId=1&devId=all&currentpagenumberbottom=1&filtername=&currentpagenumber=1&quotaactionlink=/mgr/app/action/storage.VivolQuotaAction&ascending=true&currentpagesize=20&ignoreErrorMessages=true&pageindex=1&sortby=name&filterpath=

Fiddler provided me with this

POST https://mgr/app/action/storage.SelectFileSystemAction/eventsubmit_doprocessselectfilesystem/ignored  
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash,   application/xaml+xml, application/x-ms-xbap, application/x-ms-application,   application/vnd.ms-xpsdocument, application/vnd.ms-excel, application/vnd.ms-powerpoint,   application/msword, */*  
Referer: https://mgr/app/action/storage.SelectFileSystemAction  /eventsubmit_doprepareselectfilesystem/ignored  
Accept-Language: en-us  
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0)  
Content-Type: application/x-www-form-urlencoded  
Accept-Encoding: gzip, deflate  
Host: arc  
Content-Length: 378  
Connection: Keep-Alive  
Cache-Control: no-cache  
Cookie: jid=asdsad ; jsso = asdas2sa    
op=&selectFS_devId=all&selectFS_previous_template=&selectFS_evsId=2&selectFS_currentNameSpace=&selectFS_action_class=storage.VivolAction&selectFS_action_method=doPreparevivollist&selectFS_uniqueId=13655b454e3951462f&selectFS_dont_alter_current=false&selectFS_disableReplicationTargets=true&selectFS_disableReadCache=true&selectFS_disableWorm=false&selectFS_disableUnmounted=true

I can see the electFS_devId=all and selectFS_evsId=2 in there, I need to change the EVSID but I'm not sure how to contruct the URL. Yes I changed the cookie id's

Kara
  • 6,115
  • 16
  • 50
  • 57

3 Answers3

0

Your javascript is just setting the form values for what are probably hidden fields on the form before performing the submit. You'll need to do a POST request, the same way that you do for the login.

Look at the action value on the form tag in your HTML to determine where to submit the data and put the following form items into your postData:

  1. selectFS_devId
  2. selectFS_currentNameSpace
  3. selectFS_evsId

You can use something like:

string postData = string.Format("selectFS_currentNameSpace={0}&selectFS_evsId={1}&selectFS_devId={2}", "", "2", "all");

Looks like this will get involved, because it appears to be doing some form of session or transaction tracking using selectFS_uniqueId you'll likely have to do a GET operation first and then extract that value from the form. Also, notice that your submit location, just like with the prior j_security_check, isn't going to the same location for the POST (doprocess) as the GET (doprepare) that retrieves the form.

GET https://mgr/app/action/storage.SelectFileSystemAction/eventsubmit_doprepareselectfilesystem/ignored

POST https://mgr/app/action/storage.SelectFileSystemAction/eventsubmit_doprocessselectfilesystem/ignored

Take another look at your post values here too. Clearly there is a command being issued with a class (selectFS_action_class) and method (selectFS_action_method) and likely nothing will be done if they aren't specified.

op=
&selectFS_devId=all
&selectFS_previous_template=
&selectFS_evsId=2
&selectFS_currentNameSpace=
&selectFS_action_class=storage.VivolAction
&selectFS_action_method=doPreparevivollist
&selectFS_uniqueId=13655b454e3951462f
&selectFS_dont_alter_current=false
&selectFS_disableReplicationTargets=true
&selectFS_disableReadCache=true
&selectFS_disableWorm=false
&selectFS_disableUnmounted=true

Rather than writing all this stuff to emulate a user doing operations through the web interface, have you checked with F5 to see if they have web services that you can call to do this?

JamieSee
  • 12,696
  • 2
  • 31
  • 47
  • I wish it was that simple, those don't actually exist other than in the javascript –  Mar 27 '12 at 17:01
  • You may be dealing with dynamically created elements then. The process should be pretty much the same. What happened when you tried it? Have you examined what came back in your responseContent for errors or validation warnings? Were there any exceptions thrown? Also, you may need to include values for other input elements on the form that aren't in the javascript for it to work. – JamieSee Mar 27 '12 at 17:29
  • What comes back is the page however, none of the contents are loaded. –  Mar 27 '12 at 17:32
  • also currentNameSpace always = "", I was hoping to manipulate the URL and keep this simple –  Mar 27 '12 at 17:33
  • Depending on how the web application is coded, it may not respond to the URL query string? Have you been able to manually create a URL that does what you want? Does your "something like" in the question actually work? – JamieSee Mar 27 '12 at 19:04
  • Not using fiddler I was able to pull out this in the text view, now sure how to construct it to a URL yet, any help out be awesome. –  Mar 27 '12 at 19:48
  • I cant believe i edited the wrong post please ignore my edit on your post and see the edit on my post –  Mar 27 '12 at 19:49
  • It's ok, Mike. Everybody has a bad day sometimes. I rejected the accidental edit. I've also edited the answer with some more information based on your Fiddler data. – JamieSee Mar 27 '12 at 21:16
0

Maybe the ploblem is that, the parameters in this form "j_username=user&j_password=user&submit=Send" are parameters for HTTP "GET" not "POST" you can try get the parameters on this way. C#

var operacion = context.Request.Form[0] "POST"
var operacion = context.Request.Params[0];

or

Request.Querystring("parameterName") for "GET"

or in javascript you can use $_GET or $_POST

-1

I think your question is way to long for what you are asking. plus you didn't show any code about the posting in the browser.

it seems like you just want to know how to get a form post to work...I noticed you aren't setting the contentlength property...that might have something to do with it. also, check out this "post"...

How to post data to specific URL using WebClient in C#

Community
  • 1
  • 1
Timmerz
  • 6,090
  • 5
  • 36
  • 49
  • Sorry, I don't follow. I posted a theoretical URL, obviously that URL doesn't work. What code am I looking for that "posts" in the browser. The URL doesn't change... –  Mar 27 '12 at 16:52
  • I don't follow what you just wrote. Are we in the same conversation? – Timmerz Mar 27 '12 at 16:55