• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Network Management Development
2
3## What are the data formats supported by extraData in an HTTP request?
4
5Applicable to: OpenHarmony 3.2 Beta (API version 9)
6
7**Solution**
8
9**extraData** indicates additional data in an HTTP request. It varies depending on the HTTP request method.
10
11-   If the HTTP request uses a POST or PUT method, **extraData** serves as the content of the HTTP request.
12-   If the HTTP request uses a GET, OPTIONS, DELETE, TRACE, or CONNECT method, **extraData** serves as a supplement to the HTTP request parameters and will be added to the URL when the request is sent.
13-   If you pass in a string object, **extraData** contains the string encoded on your own.
14
15## What does error code 28 mean in the response to an HTTP request?
16
17Applicable to: OpenHarmony 3.2 Beta (API version 9)
18
19**Symptom**
20
21Error code 28 is reported after an HTTP request is initiated.
22
23**Solution**
24
25Error code 28 indicates **CURLE\_OPERATION\_TIMEDOUT**, which means a libcurl library operation timeout. For details, see any HTTP status code description available.
26
27**Reference**
28
29[Common HTTP Response Codes](../reference/apis/js-apis-http.md#responsecode) and [Curl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html)
30
31## What does error code 6 mean in the response to an HTTP request?
32
33Applicable to: OpenHarmony 3.2 Beta (API version 9)
34
35**Symptom**
36
37Error code 6 is reported after an HTTP request is initiated.
38
39**Solution**
40
41Error code 6 indicates a failure to resolve the host in the address. You can ping the URL carried in the request to check whether the host is accessible.
42
43**Reference**
44
45[Common HTTP Response Codes](../reference/apis/js-apis-http.md#responsecode) and [Curl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html)
46
47## How are parameters passed to queryParams of the POST request initiated by @ohos/axios?
48
49Applicable to: OpenHarmony 3.2 Beta (API version 9)
50
51**Symptom**
52
53How are parameters passed to **queryParams** when the third-party component @ohos/axios initiates a POST request?
54
55**Solution**
56
57-   Method 1: Have the **axios.post** API receive only one parameter. The **Url.URLSearchParams** parameter needs to be converted into a string and appended to the end of the URL.
58
59    ```
60    let params:Url.URLSearchParams = new Url.URLSearchParams()
61    params.append('ctl', 'sug')
62    params.append('query', 'wangjunkai')
63    params.append('cfrom', '1099a')
64    axios.post('http://10.100.195.234:3000/save?' + params.toString()).then(res => {
65      this.message = "request result: " + JSON.stringify(res.data);
66    }).catch(err => {
67      this.message = "request error: " + err.message;
68    })
69    ```
70
71-   Method 2: Have the **axios** API receive only one **config** object. The request parameters are written in **params** of the **config** object.
72
73    ```
74    axios({
75      url: 'http://10.100.195.234:3000/save',
76      method: 'post',
77      params: {
78      ctl: 'sug',
79      query: 'wangjunkai',
80      cfrom: '1099a'
81      }
82    }).then(res => {
83      this.message = "request result: " + JSON.stringify(res.data);
84    }).catch(err => {
85      this.message = "request error: " + err.message;
86    })
87    ```
88
89
90## What should I do if no data is returned after connection.getNetCapabilities\(mNetHandle\) is called?
91
92Applicable to: OpenHarmony 3.2 Beta 2 (API version 9)
93
94**Symptom**
95
96No data is returned after **connection.getNetCapabilities\(\)** is called. What should I do?
97
98**Possible Cause**
99
100This problem is due to incorrect pointing of the **this** object. You are expected to use **\(err,data\)=\>\{\}** instead of **function\(err,data\)** to access the callback function to obtain the return result. The reason is that the function declared by **function** has its own **this** object and therefore cannot point to the **globalThis** object.
101
102**Solution**
103
104Change **function\(err,data\)** to **\(err,data\)** for the second parameter of **getNetCapabilities**.
105
106## How is data in HTTP requests transmitted in JSON format?
107
108Applicable to: OpenHarmony 3.2 Beta (API version 9)
109
110**Solution**
111
112In the HTTP message header, **Content-Type** is used to indicate the media type information. It tells the server how to process the requested data and tells the client (usually a browser) how to parse the response data, for example, displaying an image, parsing HTML, or displaying only the text.
113
114To transmit data in HTTP requests in JSON format, set **Content-Type** to **application/json**.
115
116```
117this.options = {
118  method:  http.RequestMethod.GET,
119  extraData: this.extraData,
120  header: { 'Content-Type': 'application/json' },
121  readTimeout: 50000,
122  connectTimeout: 50000
123}
124```
125
126## How do I upload photos taken by a camera to the server?
127
128Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
129
130**Symptom**
131
132After an application calls the camera to take a photo, how do I upload the photo to the server?
133
134**Solution**
135
136After the application is started and the permission is obtained, have the system access the remote server and transfer the locally saved photos to the remote server through the upload API.
137
138**Reference**
139
140[Upload and Download](../reference/apis/js-apis-request.md)
141
142## What should I do if calling connection.hasDefaultNet\(\) fails even when the network is normal?
143
144Applicable to: OpenHarmony 3.2 Beta (API version 9)
145
146**Symptom**
147
148The network connection is normal, and web pages can be opened properly on the browser. However, calling the **hasDefaultNet** fails, and the callback function returns an error.
149
150**Solution**
151
152Declare the **ohos.permission.GET\_NETWORK\_INFO** permission when calling **connection.hasDefaultNet**.
153
154For details, see [Applying for Permissions](../security/accesstoken-guidelines.md).
155
156## What does netId mean in the netHandle object returned by connection.getDefaultNet?
157
158Applicable to: OpenHarmony 3.2 Beta (API version 9)
159
160**Symptom**
161
162What are the meanings of the values of **netId**, such as **0** and **100**?
163
164**Solution**
165
166If the value of **netId** is **0**, no network connection is available. In such a case, check and rectify network faults. If the value is greater than or equal to **100**, the network connection is normal.
167
168## How do I use HTTP requests to obtain data from the network?
169
170Applicable to: OpenHarmony 3.2 Beta (API version 9)
171
172**Solution**
173
174Use the **@ohos.net.http** module to initiate an HTTP request.
175
1761.  Import the **http** module and create an HTTP request.
1772.  Set the request URL and parameters and initiate the HTTP request.
1783.  Obtain the response and parse the data.
179
180**Reference**
181
182[HTTP Data Request](../connectivity/http-request.md)
183
184## How do I encapsulate network requests by using JavaScript?
185
186Applicable to: OpenHarmony 3.2 Beta (API version 9)
187
188**Solution**
189
190OpenHarmony supports the JavaScript development mode. You can directly use JavaScript to encapsulate network requests. For details, see [Network Connection](../reference/apis/js-apis-http.md).
191
192## How do I write network requests when developing a JavaScript-based application for smart watches?
193
194Applicable to: OpenHarmony 3.2 Beta (API version 9)
195
196**Solution**
197
198OpenHarmony supports the JavaScript development mode. You can directly use JavaScript to encapsulate network requests. For details, see [Network Connection](../reference/apis/js-apis-http.md).
199
200## Why does an application fail to start after the ohos.permission.NOTIFICATION\_CONTROLLER permission is declared?
201
202Applicable to: OpenHarmony 3.2 Beta (API version 9)
203
204**Symptom**
205
206When an application is started, the following error message is reported w: error: install failed due to grant request permissions failed.
207
208**Solution**
209
210The **ohos.permission.NOTIFICATION\_CONTROLLER** permission is a **system core** permission and is not available for third-party applications.
211
212## What should I do if an error is reported when wifi.getIpInfo\(\).ipAddress is used in the Wi-Fi module?
213
214Applicable to: OpenHarmony 3.2 Beta (API version 9)
215
216**Symptom**
217
218When **wifi.getIpInfo\(\).ipAddress** is used in the Wi-Fi module, the following error message is reported: Error: assertion \(wifiDevicePtr != nullptr\) failed: Wifi device instance is null.
219
220**Solution**
221
222This problem is due to insufficient permissions. Check whether you have applied for the required permissions. For details, see [Permission Management](../security/accesstoken-overview.md).
223