How do I make a case request from the Pacer.gov API?
up vote
2
down vote
favorite
I am trying to make a request to an API called Pacer.gov. I'm expecting a file to be returned, but I'm not getting it. Can someone help me with what I'm missing?
So my C# Rest call looks like this:
(The variable PacerSession is the authentication cookie I got (with help from @jonathon-reinhart); read more about that here: How do I use RestSharp to POST a login and password to an API?)
var client = new RestClient("https://pcl.uscourts.gov/dquery");
client.CookieContainer = new System.Net.CookieContainer();
//var request = new RestRequest("/dquery", Method.POST);
var request = new RestRequest(Method.POST);
request.AddParameter("download", "1");
request.AddParameter("dl_fmt", "xml");
request.AddParameter("party", "Moncrief");
request.AddHeader("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
request.AddHeader("content-type", "text/plain; charset=utf-8");
request.AddHeader("accept", "*/*");
request.AddHeader("accept-encoding", "gzip, deflate, sdch");
request.AddHeader("accept-language", "en-US,en;q=0.8");
request.AddHeader("cookie", "PacerSession=" + PacerSession);
IRestResponse response = client.Execute(request);
If I just type the URL https://pcl.uscourts.gov/dquery?download=1&dl_fmt=xml&party=Moncrief into Chrome, I get back an XML file. When I look at the IRestResponse, I don't see anything that looks like a file. Is there something wrong with my request or am I getting the file back and just need to know how to retrieve it?
Here's part of the file I get back if I use the URL directly in the browser:
Here's what I see in VS when I debug it and look at the IRestResponse variable:
UPDATE - 6/3/16
Received this response from Pacer tech support:
In the Advanced REST Client, you will see a HTTP 302 response (a redirect to another page). In a normal browser, the redirect is automatically followed without the user seeing anything (even on the URL in the browser).
The ARC does not automatically follow that redirect to the target page.
You can see in the header of the response the target URL that has the results.
If you manually cut and paste this URL to the ARC as a HTTP GET request, you will get the XML results. I have never used C#, but there is usually a property associated with web clients that will force the client to follow the redirect.
I tried adding this:
client.FollowRedirects = true;
but I'm still not seeing an xml file when I debug this code:
IRestResponse response = client.Execute(request);
How do I get the file? Is there something I have to do to get the file from the URL it's being redirected to?
c# rest post httpresponse restsharp
add a comment |
up vote
2
down vote
favorite
I am trying to make a request to an API called Pacer.gov. I'm expecting a file to be returned, but I'm not getting it. Can someone help me with what I'm missing?
So my C# Rest call looks like this:
(The variable PacerSession is the authentication cookie I got (with help from @jonathon-reinhart); read more about that here: How do I use RestSharp to POST a login and password to an API?)
var client = new RestClient("https://pcl.uscourts.gov/dquery");
client.CookieContainer = new System.Net.CookieContainer();
//var request = new RestRequest("/dquery", Method.POST);
var request = new RestRequest(Method.POST);
request.AddParameter("download", "1");
request.AddParameter("dl_fmt", "xml");
request.AddParameter("party", "Moncrief");
request.AddHeader("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
request.AddHeader("content-type", "text/plain; charset=utf-8");
request.AddHeader("accept", "*/*");
request.AddHeader("accept-encoding", "gzip, deflate, sdch");
request.AddHeader("accept-language", "en-US,en;q=0.8");
request.AddHeader("cookie", "PacerSession=" + PacerSession);
IRestResponse response = client.Execute(request);
If I just type the URL https://pcl.uscourts.gov/dquery?download=1&dl_fmt=xml&party=Moncrief into Chrome, I get back an XML file. When I look at the IRestResponse, I don't see anything that looks like a file. Is there something wrong with my request or am I getting the file back and just need to know how to retrieve it?
Here's part of the file I get back if I use the URL directly in the browser:
Here's what I see in VS when I debug it and look at the IRestResponse variable:
UPDATE - 6/3/16
Received this response from Pacer tech support:
In the Advanced REST Client, you will see a HTTP 302 response (a redirect to another page). In a normal browser, the redirect is automatically followed without the user seeing anything (even on the URL in the browser).
The ARC does not automatically follow that redirect to the target page.
You can see in the header of the response the target URL that has the results.
If you manually cut and paste this URL to the ARC as a HTTP GET request, you will get the XML results. I have never used C#, but there is usually a property associated with web clients that will force the client to follow the redirect.
I tried adding this:
client.FollowRedirects = true;
but I'm still not seeing an xml file when I debug this code:
IRestResponse response = client.Execute(request);
How do I get the file? Is there something I have to do to get the file from the URL it's being redirected to?
c# rest post httpresponse restsharp
1
From your debugger screenshot, the content type is not xml. It's a webpage. Specifically, the Pacer login page. Even more specifically the pacer login page with a redirect to the search page. (Look at theContentType
property, and theResponseUri
property)
– theB
Jun 3 '16 at 18:29
Thanks for responding @theB. From what I got from Pacer tech support, it sounds like the request is being redirected. I tried turning the FollowRedirects option on, but I'm still not seeing the xml file. How do I get the file from this redirected page? I updated my original question with the information from Pacer.
– boilers222
Jun 3 '16 at 19:30
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am trying to make a request to an API called Pacer.gov. I'm expecting a file to be returned, but I'm not getting it. Can someone help me with what I'm missing?
So my C# Rest call looks like this:
(The variable PacerSession is the authentication cookie I got (with help from @jonathon-reinhart); read more about that here: How do I use RestSharp to POST a login and password to an API?)
var client = new RestClient("https://pcl.uscourts.gov/dquery");
client.CookieContainer = new System.Net.CookieContainer();
//var request = new RestRequest("/dquery", Method.POST);
var request = new RestRequest(Method.POST);
request.AddParameter("download", "1");
request.AddParameter("dl_fmt", "xml");
request.AddParameter("party", "Moncrief");
request.AddHeader("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
request.AddHeader("content-type", "text/plain; charset=utf-8");
request.AddHeader("accept", "*/*");
request.AddHeader("accept-encoding", "gzip, deflate, sdch");
request.AddHeader("accept-language", "en-US,en;q=0.8");
request.AddHeader("cookie", "PacerSession=" + PacerSession);
IRestResponse response = client.Execute(request);
If I just type the URL https://pcl.uscourts.gov/dquery?download=1&dl_fmt=xml&party=Moncrief into Chrome, I get back an XML file. When I look at the IRestResponse, I don't see anything that looks like a file. Is there something wrong with my request or am I getting the file back and just need to know how to retrieve it?
Here's part of the file I get back if I use the URL directly in the browser:
Here's what I see in VS when I debug it and look at the IRestResponse variable:
UPDATE - 6/3/16
Received this response from Pacer tech support:
In the Advanced REST Client, you will see a HTTP 302 response (a redirect to another page). In a normal browser, the redirect is automatically followed without the user seeing anything (even on the URL in the browser).
The ARC does not automatically follow that redirect to the target page.
You can see in the header of the response the target URL that has the results.
If you manually cut and paste this URL to the ARC as a HTTP GET request, you will get the XML results. I have never used C#, but there is usually a property associated with web clients that will force the client to follow the redirect.
I tried adding this:
client.FollowRedirects = true;
but I'm still not seeing an xml file when I debug this code:
IRestResponse response = client.Execute(request);
How do I get the file? Is there something I have to do to get the file from the URL it's being redirected to?
c# rest post httpresponse restsharp
I am trying to make a request to an API called Pacer.gov. I'm expecting a file to be returned, but I'm not getting it. Can someone help me with what I'm missing?
So my C# Rest call looks like this:
(The variable PacerSession is the authentication cookie I got (with help from @jonathon-reinhart); read more about that here: How do I use RestSharp to POST a login and password to an API?)
var client = new RestClient("https://pcl.uscourts.gov/dquery");
client.CookieContainer = new System.Net.CookieContainer();
//var request = new RestRequest("/dquery", Method.POST);
var request = new RestRequest(Method.POST);
request.AddParameter("download", "1");
request.AddParameter("dl_fmt", "xml");
request.AddParameter("party", "Moncrief");
request.AddHeader("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
request.AddHeader("content-type", "text/plain; charset=utf-8");
request.AddHeader("accept", "*/*");
request.AddHeader("accept-encoding", "gzip, deflate, sdch");
request.AddHeader("accept-language", "en-US,en;q=0.8");
request.AddHeader("cookie", "PacerSession=" + PacerSession);
IRestResponse response = client.Execute(request);
If I just type the URL https://pcl.uscourts.gov/dquery?download=1&dl_fmt=xml&party=Moncrief into Chrome, I get back an XML file. When I look at the IRestResponse, I don't see anything that looks like a file. Is there something wrong with my request or am I getting the file back and just need to know how to retrieve it?
Here's part of the file I get back if I use the URL directly in the browser:
Here's what I see in VS when I debug it and look at the IRestResponse variable:
UPDATE - 6/3/16
Received this response from Pacer tech support:
In the Advanced REST Client, you will see a HTTP 302 response (a redirect to another page). In a normal browser, the redirect is automatically followed without the user seeing anything (even on the URL in the browser).
The ARC does not automatically follow that redirect to the target page.
You can see in the header of the response the target URL that has the results.
If you manually cut and paste this URL to the ARC as a HTTP GET request, you will get the XML results. I have never used C#, but there is usually a property associated with web clients that will force the client to follow the redirect.
I tried adding this:
client.FollowRedirects = true;
but I'm still not seeing an xml file when I debug this code:
IRestResponse response = client.Execute(request);
How do I get the file? Is there something I have to do to get the file from the URL it's being redirected to?
c# rest post httpresponse restsharp
c# rest post httpresponse restsharp
edited May 23 '17 at 10:29
Community♦
11
11
asked Jun 3 '16 at 18:13
boilers222
78131530
78131530
1
From your debugger screenshot, the content type is not xml. It's a webpage. Specifically, the Pacer login page. Even more specifically the pacer login page with a redirect to the search page. (Look at theContentType
property, and theResponseUri
property)
– theB
Jun 3 '16 at 18:29
Thanks for responding @theB. From what I got from Pacer tech support, it sounds like the request is being redirected. I tried turning the FollowRedirects option on, but I'm still not seeing the xml file. How do I get the file from this redirected page? I updated my original question with the information from Pacer.
– boilers222
Jun 3 '16 at 19:30
add a comment |
1
From your debugger screenshot, the content type is not xml. It's a webpage. Specifically, the Pacer login page. Even more specifically the pacer login page with a redirect to the search page. (Look at theContentType
property, and theResponseUri
property)
– theB
Jun 3 '16 at 18:29
Thanks for responding @theB. From what I got from Pacer tech support, it sounds like the request is being redirected. I tried turning the FollowRedirects option on, but I'm still not seeing the xml file. How do I get the file from this redirected page? I updated my original question with the information from Pacer.
– boilers222
Jun 3 '16 at 19:30
1
1
From your debugger screenshot, the content type is not xml. It's a webpage. Specifically, the Pacer login page. Even more specifically the pacer login page with a redirect to the search page. (Look at the
ContentType
property, and the ResponseUri
property)– theB
Jun 3 '16 at 18:29
From your debugger screenshot, the content type is not xml. It's a webpage. Specifically, the Pacer login page. Even more specifically the pacer login page with a redirect to the search page. (Look at the
ContentType
property, and the ResponseUri
property)– theB
Jun 3 '16 at 18:29
Thanks for responding @theB. From what I got from Pacer tech support, it sounds like the request is being redirected. I tried turning the FollowRedirects option on, but I'm still not seeing the xml file. How do I get the file from this redirected page? I updated my original question with the information from Pacer.
– boilers222
Jun 3 '16 at 19:30
Thanks for responding @theB. From what I got from Pacer tech support, it sounds like the request is being redirected. I tried turning the FollowRedirects option on, but I'm still not seeing the xml file. How do I get the file from this redirected page? I updated my original question with the information from Pacer.
– boilers222
Jun 3 '16 at 19:30
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
There's one major problem with your code. You're only carrying one of the three cookies that checp-pacer-passwd.pl
returns. You need to preserve all three. The following code is a possible implementation of this, with some notes afterwards.
public class PacerClient
private CookieContainer m_Cookies = new CookieContainer();
public string Username get; set;
public string Password get; set;
public PacerClient(string username, string password)
this.Username = username;
this.Password = password;
public void Connect()
var client = new RestClient("https://pacer.login.uscourts.gov");
client.CookieContainer = this.m_Cookies;
RestRequest request = new RestRequest("/cgi-bin/check-pacer-passwd.pl", Method.POST);
request.AddParameter("loginid", this.Username);
request.AddParameter("passwd", this.Password);
IRestResponse response = client.Execute(request);
if (response.Cookies.Count < 1)
throw new WebException("No cookies returned.");
public XmlDocument SearchParty(string partyName)
string requestUri = $"/dquery?download=1&dl_fmt=xml&party=partyName";
var client = new RestClient("https://pcl.uscourts.gov");
client.CookieContainer = this.m_Cookies;
var request = new RestRequest(requestUri);
IRestResponse response = client.Execute(request);
if (!String.IsNullOrEmpty(response.Content))
XmlDocument result = new XmlDocument();
result.LoadXml(response.Content);
return result;
else return null;
It's easiest to just keep a hold of the CookieContainer
throughout the entire time you're working with Pacer. I wrapped the functionality into a class, just to make it a little easier to package up with this answer, but you can implement it however you want. I didn't put in any real error checking, so you probably want to check that response.ResponseUri
is actually the search page and not the logon page, and that the content is actually well-formed XML.
I've tested this using my own Pacer account, like so:
PacerClient client = new PacerClient(Username, Password);
client.Connect();
var document = client.SearchParty("Moncrief");
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
There's one major problem with your code. You're only carrying one of the three cookies that checp-pacer-passwd.pl
returns. You need to preserve all three. The following code is a possible implementation of this, with some notes afterwards.
public class PacerClient
private CookieContainer m_Cookies = new CookieContainer();
public string Username get; set;
public string Password get; set;
public PacerClient(string username, string password)
this.Username = username;
this.Password = password;
public void Connect()
var client = new RestClient("https://pacer.login.uscourts.gov");
client.CookieContainer = this.m_Cookies;
RestRequest request = new RestRequest("/cgi-bin/check-pacer-passwd.pl", Method.POST);
request.AddParameter("loginid", this.Username);
request.AddParameter("passwd", this.Password);
IRestResponse response = client.Execute(request);
if (response.Cookies.Count < 1)
throw new WebException("No cookies returned.");
public XmlDocument SearchParty(string partyName)
string requestUri = $"/dquery?download=1&dl_fmt=xml&party=partyName";
var client = new RestClient("https://pcl.uscourts.gov");
client.CookieContainer = this.m_Cookies;
var request = new RestRequest(requestUri);
IRestResponse response = client.Execute(request);
if (!String.IsNullOrEmpty(response.Content))
XmlDocument result = new XmlDocument();
result.LoadXml(response.Content);
return result;
else return null;
It's easiest to just keep a hold of the CookieContainer
throughout the entire time you're working with Pacer. I wrapped the functionality into a class, just to make it a little easier to package up with this answer, but you can implement it however you want. I didn't put in any real error checking, so you probably want to check that response.ResponseUri
is actually the search page and not the logon page, and that the content is actually well-formed XML.
I've tested this using my own Pacer account, like so:
PacerClient client = new PacerClient(Username, Password);
client.Connect();
var document = client.SearchParty("Moncrief");
add a comment |
up vote
0
down vote
There's one major problem with your code. You're only carrying one of the three cookies that checp-pacer-passwd.pl
returns. You need to preserve all three. The following code is a possible implementation of this, with some notes afterwards.
public class PacerClient
private CookieContainer m_Cookies = new CookieContainer();
public string Username get; set;
public string Password get; set;
public PacerClient(string username, string password)
this.Username = username;
this.Password = password;
public void Connect()
var client = new RestClient("https://pacer.login.uscourts.gov");
client.CookieContainer = this.m_Cookies;
RestRequest request = new RestRequest("/cgi-bin/check-pacer-passwd.pl", Method.POST);
request.AddParameter("loginid", this.Username);
request.AddParameter("passwd", this.Password);
IRestResponse response = client.Execute(request);
if (response.Cookies.Count < 1)
throw new WebException("No cookies returned.");
public XmlDocument SearchParty(string partyName)
string requestUri = $"/dquery?download=1&dl_fmt=xml&party=partyName";
var client = new RestClient("https://pcl.uscourts.gov");
client.CookieContainer = this.m_Cookies;
var request = new RestRequest(requestUri);
IRestResponse response = client.Execute(request);
if (!String.IsNullOrEmpty(response.Content))
XmlDocument result = new XmlDocument();
result.LoadXml(response.Content);
return result;
else return null;
It's easiest to just keep a hold of the CookieContainer
throughout the entire time you're working with Pacer. I wrapped the functionality into a class, just to make it a little easier to package up with this answer, but you can implement it however you want. I didn't put in any real error checking, so you probably want to check that response.ResponseUri
is actually the search page and not the logon page, and that the content is actually well-formed XML.
I've tested this using my own Pacer account, like so:
PacerClient client = new PacerClient(Username, Password);
client.Connect();
var document = client.SearchParty("Moncrief");
add a comment |
up vote
0
down vote
up vote
0
down vote
There's one major problem with your code. You're only carrying one of the three cookies that checp-pacer-passwd.pl
returns. You need to preserve all three. The following code is a possible implementation of this, with some notes afterwards.
public class PacerClient
private CookieContainer m_Cookies = new CookieContainer();
public string Username get; set;
public string Password get; set;
public PacerClient(string username, string password)
this.Username = username;
this.Password = password;
public void Connect()
var client = new RestClient("https://pacer.login.uscourts.gov");
client.CookieContainer = this.m_Cookies;
RestRequest request = new RestRequest("/cgi-bin/check-pacer-passwd.pl", Method.POST);
request.AddParameter("loginid", this.Username);
request.AddParameter("passwd", this.Password);
IRestResponse response = client.Execute(request);
if (response.Cookies.Count < 1)
throw new WebException("No cookies returned.");
public XmlDocument SearchParty(string partyName)
string requestUri = $"/dquery?download=1&dl_fmt=xml&party=partyName";
var client = new RestClient("https://pcl.uscourts.gov");
client.CookieContainer = this.m_Cookies;
var request = new RestRequest(requestUri);
IRestResponse response = client.Execute(request);
if (!String.IsNullOrEmpty(response.Content))
XmlDocument result = new XmlDocument();
result.LoadXml(response.Content);
return result;
else return null;
It's easiest to just keep a hold of the CookieContainer
throughout the entire time you're working with Pacer. I wrapped the functionality into a class, just to make it a little easier to package up with this answer, but you can implement it however you want. I didn't put in any real error checking, so you probably want to check that response.ResponseUri
is actually the search page and not the logon page, and that the content is actually well-formed XML.
I've tested this using my own Pacer account, like so:
PacerClient client = new PacerClient(Username, Password);
client.Connect();
var document = client.SearchParty("Moncrief");
There's one major problem with your code. You're only carrying one of the three cookies that checp-pacer-passwd.pl
returns. You need to preserve all three. The following code is a possible implementation of this, with some notes afterwards.
public class PacerClient
private CookieContainer m_Cookies = new CookieContainer();
public string Username get; set;
public string Password get; set;
public PacerClient(string username, string password)
this.Username = username;
this.Password = password;
public void Connect()
var client = new RestClient("https://pacer.login.uscourts.gov");
client.CookieContainer = this.m_Cookies;
RestRequest request = new RestRequest("/cgi-bin/check-pacer-passwd.pl", Method.POST);
request.AddParameter("loginid", this.Username);
request.AddParameter("passwd", this.Password);
IRestResponse response = client.Execute(request);
if (response.Cookies.Count < 1)
throw new WebException("No cookies returned.");
public XmlDocument SearchParty(string partyName)
string requestUri = $"/dquery?download=1&dl_fmt=xml&party=partyName";
var client = new RestClient("https://pcl.uscourts.gov");
client.CookieContainer = this.m_Cookies;
var request = new RestRequest(requestUri);
IRestResponse response = client.Execute(request);
if (!String.IsNullOrEmpty(response.Content))
XmlDocument result = new XmlDocument();
result.LoadXml(response.Content);
return result;
else return null;
It's easiest to just keep a hold of the CookieContainer
throughout the entire time you're working with Pacer. I wrapped the functionality into a class, just to make it a little easier to package up with this answer, but you can implement it however you want. I didn't put in any real error checking, so you probably want to check that response.ResponseUri
is actually the search page and not the logon page, and that the content is actually well-formed XML.
I've tested this using my own Pacer account, like so:
PacerClient client = new PacerClient(Username, Password);
client.Connect();
var document = client.SearchParty("Moncrief");
answered Jun 3 '16 at 23:34
theB
5,16512134
5,16512134
add a comment |
add a comment |
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%2f37620997%2fhow-do-i-make-a-case-request-from-the-pacer-gov-api%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
1
From your debugger screenshot, the content type is not xml. It's a webpage. Specifically, the Pacer login page. Even more specifically the pacer login page with a redirect to the search page. (Look at the
ContentType
property, and theResponseUri
property)– theB
Jun 3 '16 at 18:29
Thanks for responding @theB. From what I got from Pacer tech support, it sounds like the request is being redirected. I tried turning the FollowRedirects option on, but I'm still not seeing the xml file. How do I get the file from this redirected page? I updated my original question with the information from Pacer.
– boilers222
Jun 3 '16 at 19:30