[jira] Commented: (HTTPCLIENT-1064) ExecutionContext returning HttpUriRequest with invalid URI (missing host)

2011-03-06 Thread Ted Troccola (JIRA)

[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1064?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13003118#comment-13003118
 ] 

Ted Troccola commented on HTTPCLIENT-1064:
--

Oleg,

Any idea why the following code doesn't follow the 302 automatically?

---
public static void main(String[] args) throws ClientProtocolException,
IOException
 {

// TODO: Delete after fixing problem in main_BUG()

 String url = "http://www.wc3c.net/register.php";;

HttpParams httpParams = new BasicHttpParams();
 HttpClient httpclient = new DefaultHttpClient(httpParams);
HttpPost httpPost = new HttpPost(url);

httpPost.addHeader(HttpHeaders.ACCEPT,
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

 List nameValuePairList = new ArrayList();
nameValuePairList.add(new BasicNameValuePair("s", ""));
 nameValuePairList.add(new BasicNameValuePair("do", "addmember"));
nameValuePairList.add(new BasicNameValuePair("url", "http%3A%2F%
2Fwww.wc3c.net%2Findex.php"));
 nameValuePairList.add(new BasicNameValuePair("agree", "1"));
nameValuePairList.add(new BasicNameValuePair("password_md5", ""));
 nameValuePairList.add(new BasicNameValuePair("passwordconfirm_md5", ""));
nameValuePairList.add(new BasicNameValuePair("day", "0"));
 nameValuePairList.add(new BasicNameValuePair("month", "0"));
nameValuePairList.add(new BasicNameValuePair("year", "0"));
 nameValuePairList.add(new BasicNameValuePair("username", "edisonar"));
nameValuePairList.add(new BasicNameValuePair("password", "TselHhW"));
 nameValuePairList.add(new BasicNameValuePair("passwordconfirm",
"TselHhW"));
nameValuePairList.add(new BasicNameValuePair("email", "[email protected]
"));
 nameValuePairList.add(new BasicNameValuePair("emailconfirm", "
[email protected]"));
 nameValuePairList.add(new BasicNameValuePair("timezoneoffset", "-7"));
nameValuePairList.add(new BasicNameValuePair("dst", "1"));
 nameValuePairList.add(new BasicNameValuePair("options[adminemail]", "1"));
nameValuePairList.add(new BasicNameValuePair("options[showemail]", "1"));
 nameValuePairList.add(new BasicNameValuePair("imabot", "Yes"));

HttpEntity paramsEntity = new UrlEncodedFormEntity(nameValuePairList,
HTTP.UTF_8);

httpPost.setEntity(paramsEntity);

HttpContext context = new BasicHttpContext();
 HttpResponse response = httpclient.execute(httpPost, context);

if ((response.getStatusLine().getStatusCode() ==
HttpStatus.SC_MOVED_TEMPORARILY))
 {
System.out.println("Why is this redirect not handled?");
}
 }
---

Thanks!!!




> ExecutionContext returning HttpUriRequest with invalid URI (missing host)
> -
>
> Key: HTTPCLIENT-1064
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1064
> Project: HttpComponents HttpClient
>  Issue Type: Bug
>  Components: HttpClient
>Affects Versions: 4.1 Final
> Environment: Windows 7, java 1.6.0.21
>Reporter: Ted Troccola
>  Labels: HttpClient
>
> The HttpUriRequest contains an invalid URI - host is null
> public static void main(String args[]) throws ClientProtocolException, 
> IOException
> {
> HttpParams httpParams = new BasicHttpParams();
> HttpClient httpclient = new DefaultHttpClient(httpParams);
> HttpGet httpGet = new HttpGet("http://www.google.com/";);
> HttpContext context = new BasicHttpContext();
> httpclient.execute(httpGet, context);
> HttpUriRequest currentReq = (HttpUriRequest) 
> context.getAttribute(ExecutionContext.HTTP_REQUEST);
> System.out.println("New URI host (why is it null?): " + 
> currentReq.getURI().getHost());
> }

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



[jira] Commented: (HTTPCLIENT-1064) ExecutionContext returning HttpUriRequest with invalid URI (missing host)

2011-03-03 Thread Oleg Kalnichevski (JIRA)

[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1064?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13001931#comment-13001931
 ] 

Oleg Kalnichevski commented on HTTPCLIENT-1064:
---

Secure connections are 'tunnelled' through HTTP proxies, so that requests 
transmitted over such connections look exactly the same as if they were 
executed directly.

In fact there is no need to bother about the proxy bit at all. You can use a 
much simpler algorithm: (1) get the request (2) get the request URI (3) if it 
is relative rewrite it using the target host from the context (4)  live happily 
ever after.

Oleg 

> ExecutionContext returning HttpUriRequest with invalid URI (missing host)
> -
>
> Key: HTTPCLIENT-1064
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1064
> Project: HttpComponents HttpClient
>  Issue Type: Bug
>  Components: HttpClient
>Affects Versions: 4.1 Final
> Environment: Windows 7, java 1.6.0.21
>Reporter: Ted Troccola
>  Labels: HttpClient
>
> The HttpUriRequest contains an invalid URI - host is null
> public static void main(String args[]) throws ClientProtocolException, 
> IOException
> {
> HttpParams httpParams = new BasicHttpParams();
> HttpClient httpclient = new DefaultHttpClient(httpParams);
> HttpGet httpGet = new HttpGet("http://www.google.com/";);
> HttpContext context = new BasicHttpContext();
> httpclient.execute(httpGet, context);
> HttpUriRequest currentReq = (HttpUriRequest) 
> context.getAttribute(ExecutionContext.HTTP_REQUEST);
> System.out.println("New URI host (why is it null?): " + 
> currentReq.getURI().getHost());
> }

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



[jira] Commented: (HTTPCLIENT-1064) ExecutionContext returning HttpUriRequest with invalid URI (missing host)

2011-03-02 Thread Ted Troccola (JIRA)

[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1064?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13001870#comment-13001870
 ] 

Ted Troccola commented on HTTPCLIENT-1064:
--

Oleg,

Thanks for the quick reply.  Your information was very helpful.  I modified
my code accordingly.

However, today I came across something that I did not expect.

When the following code is run, it produces the unexpected results.  It
seems that when a proxy is used for the HTTPS URL, my logic returns an
invalid URL.

I believe I have coded it to conform to your reply and the reference you
provided.

Any ideas - am I still missing something?

Thanks in advance,

---

public static void visit(String url, HttpHost proxy) throws
ClientProtocolException, IOException
 {
HttpParams httpParams = new BasicHttpParams();
if (proxy != null)
 {
System.out.println("Using proxy");
ConnRouteParams.setDefaultProxy(httpParams, proxy);
 }
else
{
 System.out.println("Not using proxy");
}

HttpClient httpclient = new DefaultHttpClient(httpParams);
 HttpGet httpGet = new HttpGet(url);
HttpContext context = new BasicHttpContext();
 httpclient.execute(httpGet, context);
HttpUriRequest currentReq = (HttpUriRequest)
context.getAttribute(ExecutionContext.HTTP_REQUEST);

String currentURLString;

if (((HttpHost) context.getAttribute(ExecutionContext.HTTP_PROXY_HOST) ==
null))
 {
// No proxy was used, the URI will be relative
HttpHost currentHost = (HttpHost)
context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
 currentURLString = (currentHost.toURI().toString() +
currentReq.getURI().toString()).toLowerCase();
}
 else
{
// A proxy was used, the URI will be absolute
 currentURLString = currentReq.getURI().toString().toLowerCase();
}

 System.out.println("Current URL: " + currentURLString);
}

public static void main(String args[]) throws ClientProtocolException,
IOException
{
 // A few proxies
/*
 * 118.97.224.2:3128
 202.28.66.115:8080
210.107.100.251:8080
 89.28.178.40:8080
174.142.104.57:312
 */
HttpHost proxy = new HttpHost("41.190.16.17", 8080);

 String url = "http://www.foxnews.com/";;
System.out.println("Testing: " + url);
 ApacheHttpHelper.visit(url, null);
ApacheHttpHelper.visit(url, proxy);

 url = "https://ariotek.co.uk/forums/register.php";;
System.out.println("Testing: " + url);
 ApacheHttpHelper.visit(url, null);
ApacheHttpHelper.visit(url, proxy);
}
---

Testing: http://www.foxnews.com/
Not using proxy
Current URL: http://www.foxnews.com/
Using proxy
Current URL: http://www.foxnews.com/
Testing: https://ariotek.co.uk/forums/register.php
Not using proxy
Current URL: https://ariotek.co.uk/forums/register.php
Using proxy
Current URL: /forums/register.php<--- Why is this URL not
absolute?

On Sun, Feb 27, 2011 at 12:29 PM, Oleg Kalnichevski (JIRA)



> ExecutionContext returning HttpUriRequest with invalid URI (missing host)
> -
>
> Key: HTTPCLIENT-1064
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1064
> Project: HttpComponents HttpClient
>  Issue Type: Bug
>  Components: HttpClient
>Affects Versions: 4.1 Final
> Environment: Windows 7, java 1.6.0.21
>Reporter: Ted Troccola
>  Labels: HttpClient
>
> The HttpUriRequest contains an invalid URI - host is null
> public static void main(String args[]) throws ClientProtocolException, 
> IOException
> {
> HttpParams httpParams = new BasicHttpParams();
> HttpClient httpclient = new DefaultHttpClient(httpParams);
> HttpGet httpGet = new HttpGet("http://www.google.com/";);
> HttpContext context = new BasicHttpContext();
> httpclient.execute(httpGet, context);
> HttpUriRequest currentReq = (HttpUriRequest) 
> context.getAttribute(ExecutionContext.HTTP_REQUEST);
> System.out.println("New URI host (why is it null?): " + 
> currentReq.getURI().getHost());
> }

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]