Read html from a cgi returned file: help, thanks

i have a problem with the following case.
i want to quote google's searching result in my program, and what i do it like this.
1> open a connection
URL url = new URL("http://images.google.com/images");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
2>post a parameter
PrintWriter out = new PrintWriter(connection.getOutputStream());
out.println("q=singapore+satellite+image");
out.close();
3>Read the result
BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    connection.getInputStream()));
     String inputLine;
     while ((inputLine = in.readLine()) != null)
     System.out.println(inputLine);
     in.close();
However, i get the following result:
<HTML><HEAD><TITLE>Bad Request</TITLE></HEAD>
<BODY><H1>400 Bad Request</H1>
Your client has issued a malformed or illegal request
</BODY></HTML>
Press any key to continue . . .
can anyone tell me what is wrong?
thanks a lot.
post on networking p2p.wrox.com

Try a shortcut like this:
URL url=new URL("http://www.google.com/search?hl=en&q=java");
Where the query string is in bold!
V.V.

Similar Messages

  • Read html from a cgi returned page using URL

    i have a problem with the following case.
    i want to quote google's searching result in my program, and what i do it like this.
    1> open a connection
    URL url = new URL("http://images.google.com/images");
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);
    2>post a parameter
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.println("q=singapore+satellite+image");
    out.close();
    3>Read the result
    BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        connection.getInputStream()));
         String inputLine;
         while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);
         in.close();
    However, i get the following result:
    <HTML><HEAD><TITLE>Bad Request</TITLE></HEAD>
    <BODY><H1>400 Bad Request</H1>
    Your client has issued a malformed or illegal request
    </BODY></HTML>
    Press any key to continue . . .
    can anyone tell me what is wrong?
    thanks a lot.
    post on networking p2p.wrox.com

    Without looking it up, I seem to recall there's a setMethod() method, and you give it "GET" for a parameter. But you could look that up. With the Get method, the parameters are appended to the URL after a question mark, like this:
    http://images.google.com/images?q=singapore+satellite+image
    where as with the Post method, the parameters are sent in a separate stream, the way you wrote your program. Get can usually extend only to 255 characters (or some small number like that), Post is theoretically unlimited.
    If you look at the URLs that a Google search produces, you will see that it uses the Get method.

  • Read lines from more than 1 file of different file extensions, extract the data and output to screen

    Hi,
    I am trying to read data from more than one file at once. The files are different types e.g. one is a text file one is an xml file like so, StudentInformation.txt, CollegeInformation.xml. The files are all stored in one place, in this case on the D drive of
    a local computer. I am trying to locate any files in the D drive with a file extension of .txt or of .xml (there may be more than two of these files in the future, so I'm trying to allow for that). Then I want to open all of these files, extract the information
    and output all the information in one display window. I want all the information from these two or more files to be displayed together in the display window.
    Here is the code so far. It is throwing up errors.
            //Load from txt or xml files
            private void btnLoad_Click(object sender, RoutedEventArgs e)
                    IEnumerable<string> fileContents = Directory.EnumerateFiles("D:\\", "*.*", SearchOption.TopDirectoryOnly)
                    .Select(x => new FileInfo(x))
                    .Where(x => x.Extension == ".xml" || x.Extension == ".txt")
                    .Select(file => ParseFile(file));}
                    private string ParseFile(FileInfo file)
                        try
                            using (StreamReader sr = new StreamReader(file.FullName))
                                string line;
                                while ((line = sr.ReadLine()) != null)
                                    //Logic here to determine if this is the correct file and append accordingly
                                    lbDisplay.Items.Add(line);
                                return line;
                        catch (Exception ex)
                            // Let the user know what went wrong
                            MessageBox.Show("The file could not be read: ");
                            MessageBox.Show(ex.Message);
    The error it throws up is:
    Error 1
    'BookList.MainWindow.ParseFile(System.IO.FileInfo)': not all code paths return a value

    This is the Small Basic programming language so moving to a C# forum.
    But you need all paths to return a value, including if an exception is called and it jumps to the catch, perhaps just:
    // Let the user know what went wrong
    MessageBox.Show("The file could not be read: ");
    MessageBox.Show(ex.Message);
    return "";

  • Read XML from a hardware sensor file into ODI

    Read XML from a hardware sensor file into ODI
    Hi,
    I am trying to extract xml data from a flowmeter that generates XML data.
    The xml file is found in http://ip_address/history.xml
    I’ve defined my Topology as such
    JDBC Driver: com.sunopsis.jdbc.driver.xml.SnpsXmlDriver
    JDBC URL: jdbc:snps:xml?f=http://192.168.0.202/history.xml&ro=true
    Please note to access the file I have to supply a username and password so I did in the definition But when testing my setup I get an error:
    ava.sql.SQLException: The DTD file "http://192.168.0.202/history.dtd" doesn't exist: Server redirected too many times (20)
    Please note I cannot write dtd to the device as it is a read only device.
    Has anyone came across such an issue, how can I achieve this.
    Thanks
    Hicham

    Hi David,
    Thanks for your reply.
    I've tried this jdbc url
    jdbc:snps:xml?f=http://192.168.0.202/history.xml&d=c:\temp\history.dtd
    but when I test the connection i get the following error
    java.sql.SQLException: While generating the DTD from the XML file, a java.io.IOException exception occurred saying: Server returned HTTP response code: 401 for URL: http://192.168.0.202/history.xml
    If I browse http://192.168.0.202/history.xml and i supply the username and password I get an xml page.
    I've supplied the username and password in the definition tab of the Data Server windows but still getting the above error.
    THanks
    Hicham

  • Static lookup lists:read data from a Java *.properties file

    Hi
    i need to make static lookup lists i am using read data from a Java *.properties file
    i am using the Class "PropertyFileBasedLookupViewObjectImpl" that wrote by Steve Muench in ToyStore.
    but i need to use the default language for that i update the loadDataFromPropertiesFile()
    method to find the correct properties file
    String temp=Locale.getDefault().getLanguage();
    String propertyFile =
    getViewDef().getFullName().replace('.', '/')+"_"+temp+ ".properties";
    the problem:
    For English(TEST_en.properties) it is good and working
    For Arabic(TEST_ar.properties) read from correct file _ar.properties
    but the dispaly character is wrong
    When Debug
    In the File 1=&#1583;&#1605;&#1588;&#1602;
    In debug 1=/u32423

    Depending on your use case you can either use a programmatic VO or directly expose the JV class as a data control.
    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_36/jdtut_11r2_36.html

  • Best way to browse and read data from a lot of files?

    Hi All,
    I am trying to read tags from music files. Currently I'm listing all the files and then reading through the tags, as below:
    List<File> result = new ArrayList<File>();
    FilenameFilter mp3filter = new FilenameFilter() {
         public boolean accept(File dir, String name) {
              return name.endsWith(".mp3");
    FilenameFilter wmafilter = new FilenameFilter() {
         public boolean accept(File dir, String name) {
              return name.endsWith(".wma");
    FileFilter dirFilter = new FileFilter() {
         public boolean accept(File file) {
              return file.isDirectory();
    File[] dirList = aStartingDir.listFiles(dirFilter);
    File[] mp3files = aStartingDir.listFiles(mp3filter);
    File[] wmafiles = aStartingDir.listFiles(wmafilter);
    List<File> filesDirs = Arrays.asList(dirList);
    List<File> filesMp3 = Arrays.asList(mp3files);
    List<File> filesWma = Arrays.asList(wmafiles);
    for (File file : filesMp3) {
         result.add(file);
    for (File file : filesWma) {
         result.add(file);
    for (File file : filesDirs) {
         List<File> deeperList = getFileListing(file);
         result.addAll(deeperList);
    }and then read the files in a for loop through the list.
    Is there a better way to do the same?

    Well, you could optimize that just a little bit by only calling listFiles once with a filter that would accept directories, wmas, and mp3s all in one go. Then you could iterate through the results and separate them into the three categories after you had the complete recursive directory listing. That may be faster. But your OS will likely cache the results of the directory listing, thus minimizing the effort of your current approach. But honestly, no... you need the headers from every file, so you'll need to find each file and then check the headers.
    If you want, you can cache the results somewhere for future reference. Are you concerned about performance or some such?

  • Reading character '�' from a notepad text file

    Hi, I created a text file using plain editor ( notepad), when I try to read the character '�' a got the � symbol.
    What I have to do ?
    Thanks in advance.

    Hi, and yes , at this point of time I can not resolve the problem, the problem it's not only with the �, but with �, �, � � � Spanish characters !
    They can be creted using a plain text editor, but i can not read it from java !
    Thanks a LOT again.

  • Reading data from Hashtable in another file

    how do i read the data from Hashtable which is created in another file. The file which creates hashtable is continuously running , and i want to read the content of the hash table into another file. Both the file exist in same machine.
    Help needed.
    Ancitipated Thanks

    Then you mean "class" or "object", not "file". Yes, you see the details of these classes in the source code files, and the compiled classes are kept in files, but programmers don't think of the files, they think of the objects running in the JVM. By calling them "files" you're causing confusion.
    Anyway, multiple threads can access a hashtable, which is synchronized apparently. So that alone shouldn't be a problem. If you have one object adding to a hashtable while another is reading its contents via an iterator, that could cause ConcurrentModificationExceptions.

  • Reading HTML from JSP

    Hi, I am currently doing an enterprise application and constructed a page using html with a link using HREF. When I click the link I run a jsp file. It there a way to read the name of the link into a string in the jsp file when the link is clicked? Please help I am still a bit green in jsp.
    Thank you.

    // I usr acceptCharset
    %@ page contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
    <html:form acceptCharset="UTF-8" action="/doSomthing">
    <html:text property=" firstname" />
    </html:form>
    in the action Action class
        Sysrem.out.println("Firsname: "+myForm.getFirstname())
       // ouput
        Firstname: ��ther is any method to it ???????

  • IE 5.0 hanging when one is reading HTML from Weblogic 6.0

    I have following configuration:
    Local network (TCP/IP, Wins server)
    SERVER: NT 2000 AdvServer & Weblogic Eval 6.0 Sp2 & Oracle 8.1.7
    CLIENTS
    1) Win 2000Pro & IE 5.0
    2) Win 98 & IE 5.0
    Quite often IE (client one) is hanging when one is reading static HTML pages.
    Also IE (client two) says that there is fail in Kernel and display dump of memory.
    In last case it is occured less often.
    I located these static HTML pages in Webdefault catalog.
    Also I have two simple JSP pages, one of them is genering current time and is
    working constantly.
    This situation was not changed when I did the following:
    1. Disable Java Plugin
    2. Set Weblogic Sp1.
    What did I wrong?
    Thanks in advance
    Eugenia
    [email protected]

    I play the mp3 files as sprites in the score that are
    streaming from the web server. If you selecr "Insert->Media
    Element->Shockwave Audio" from the menu in Director you can
    choose to import a mp3/swa file. This file will import as a cast
    member which will have an external link address. (e.g.
    http://www.adobe.com/mysound/myfile.mp3)
    I have then dragged this cast member onto channel 1 in the score
    spanning for instance 10 frames.
    It does not make a difference wether the soundfile is of type
    mp3 or swa, I have tried both.

  • Reading data from a static excel file

    Hi all
    I got the answer for attching excel file. But i want to read the contents from the uploaded file and save it in context variables.
    How is it done? Please reply soon. Its very urgent.
    Thanks & regards
    Aparnna

    Check this too
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/edc2f3c2-0401-0010-8898-acd5b6a94353
    Regards, Anilkumar

  • Read text from a simple PDF file

    Is it possible to extract text from a simple PDF (Non-Interactive) in ABAP? May be using the class CL_FP_PDF_OBJECT ?
    Let's say I have a pdf document with a couple of lines of text. How can I read the "actual" text in an ABAP program?
    Thanks for your help!

    Of course you can do this, but not using the standard SAP/ABAP/Adobe.
    Check for the Java library called iText. Now you think you don´t need Java, of course. If you cannot use Java, at least you can check the coding of this library and do it in ABAP for yourself.
    But there is no such a tool in standard SAP because why would one buy a Interactive form licence if it would be so easy?

  • Error from using ANT program, need help, Thanks

    Hello,
    I tried to run J2ee tutorial sample code. Following the instruction, I tried to ues ant to build a sample ConverterAPP but get some error message. I would preciate if somebody could give me some help.
    Thanks.
    Hui Lu
    [email protected]
    Following is the command I entered from an CMD window and the exception I got:
    C:\j2sdkee1.3\j2eetutorial\examples\src>ant converter
    ***Warning: I am here start runAnt.
    Exception in thread "main" java.lang.NoClassDefFoundError: Connectors\classes;C:
    \javacode\classes;C:\eGate\client\classes;C:\eGate\client\classes\egate/jar;C:\eGate\client\JRE\1/1/7B\lib\rt/jar;C:\PROGRA~1\MQSeries\java\lib\COMIBM~2/JAR;C:\
    PROGRA~\MQSeries\java\lib\COMIBM~1/JAR;C:\PROGRA~\MQSeries\java\lib\COMIBM~3/JAR;C:\PROGRA~\MQSeries\tools\javaclnt\samples\en_us;
    Warning: I am here end runAnt.
    Following is the command line in the batch file which raised Exception
    C:\jdk1.3.1_01\bin\java -classpath "C:\jdk1.3.1_01\lib\tools.jar";"C:\j2sdkee1.3\jakarta-ant-1.3\lib\parser.jar";"C:\j2sdkee1.3\jakarta-ant-1.3\lib\jaxp.jar";"C:\j2sdkee1.3\jakarta-ant-1.3\lib\ant.jar";C:\javacode\classes;C:\j2sdkee1.3\jaka
    rta-ant-1.3\bin;C:\j2sdkee1.3\bin;C:\jdk1.3.1_01\bin;C:\IBMCON~\CICS\Classes\CTGCLI~1.JAR;C:\IBMConnectors\classes;C:\javacode\classes;C:\eGate\client\classes;C:\eGate\client\classes\egate.jar;C:\eGate\client\JRE\1.1.7B\lib\rt.jar;C:\PROGRA~\MQSeries\java\lib\COMIBM~2.JAR;C:\PROGRA~\MQSeries\java\lib\COMIBM~1.JAR;C:\PROGRA~\MQSeries\java\lib\COMIBM~3.JAR;C:\PROGRA~\MQSeries\tools\javaclnt\samples\en_us;
    -Dant.home="C:\j2sdkee1.3\jakarta-ant-1.3" org.apache.tools.ant.Ma
    in converter
    ****************************************

    Obviously you have the IBM java tools installed on your PC, and your classpath starts with IBM Connectors\...
    What you need to do is to edit your classpath environment variable in control panel->systems, and use quotation marks for any long directory/file names, or directory names with spaces in them. For example, change C:\IBM Connectors\classes to "C:\IBM Connectors\classes". Then it will work.

  • I have lost my bookmarks? gone from top of page? help thanks

    bookmarks have gone altogether from top of page

    Click "View"menu  in the Safari menu bar at the top of the screen and select "Show
    Toolbar".
    or
    Click "View" menu in the Safari menu bar and click "Customize Toolbar".
    From the drop down drag the default set into the Toolbar.
      the one under " or drag the default set into the Toolbar"
    Click "Done".
    Best.

  • I have lost my most important iphoto library. I have several different photo libraries that use and the one that I have been using for this entire year disappeared when I switched back to look at photos from an old library, please help, thank you.

    I have also tried searching for them in finder and going through the trash, i have had no luck yet and confused on where they might be.

    With the amount of information you've provided it's impossible to offer a solution.  We can't see your computer so we need to know the details of your problem and setup, i.e.:
    what version of iPhoto are you using?
    what system version are you running?
    what do you see in the iPhoto window when iPhoto opens?
    what fixes have you tried?
    where is your library normally located?
    did you apply any updates or upgrades just prior to the problem occurring?
    are you running a "managed" or "referenced" library?
    how much free space on your boot drive?
    If you launch iPhoto with the Option key held down you'll get a window with all libraries that iPhoto an find.  What do you see in that window?
    If you select a library in the window it's location will be shown directly beneath that window.

Maybe you are looking for

  • How to create a response file for Acrobat 9 Pro?

    I with to collect data from a PDF form made with LiveCycle Designer. The instruction say- After a user submits a form, open the returned form. In the Add Completed Form To Responses File dialog box, select one of the following: I am totally baffled a

  • DNSBL logging in Sun MTA

    Hey, I've configured a PORT_ACCESS rule in the mappings file as follows: TCP|*|25|*|* $C$[opt/sunapps/msg/lib/dns_verify.so,dns_verify_domain_port,$1,sbl-xbl.spamhaus.org,Your$ host$ ($1)$ found$ on$ block$ list]$E This appears to be working correctl

  • I/U Elim with Equity Method

    Dear BCS SDNers, I have an issue regarding I/U Eliminations with Equity method companies. If I remember correctly in my other projects (I am not able to check it now), the system is supposed to look at the accounting techniques to determine if it has

  • Query regarding date arithmatic

    hi i want to write the procedure which will give me the difference of two dates in hours. there are two columns start_dt and end_dt and i want to calculate the difference between them in hours. morever i want to add functionality like if the start or

  • Fireworks Effect in Flash

    Hi all, I've been searching for a cool fireworks effect, and finally found this one: http://www.wipeout44.com/tutorials/flash_fireworks.asp I'm doing everything as explained, but cant get it to work. If anyone could give me an idea how to create an e